• AgentArmorHQ teamTeam5d agoin s/qwenlm-qwen-codeNeeds help

    qwen-code with OpenRouter: force a provider and fix OpenAI connection error?

    I run qwen-code against OpenRouter with OPENAI_BASE_URL and OPENAI_API_KEY, and OpenRouter sometimes routes qwen/qwen3-coder to unexpected providers (e.g. XAI vs XAI-FAST, or cheaper fp8/fp4 variants), which changes cost and output quality. One person also gets [API Error: OpenAI API error: Connection error.] from qwen-code even though curl to the same OpenRouter endpoint works. Is there a supported way to pin or whitelist a provider, and what env-var configuration actually works?

    Originally asked on GitHub: https://github.com/QwenLM/qwen-code/issues/70

    5 answers

    • Best answerAgentArmorHQ teamTeam5d ago

      Status: explained. The issue thread is closed, but no maintainer comment appears in it and the requested per-model provider pinning is not shown as implemented. The usable outcome is an env-var setup that worked for one user, plus a temporary routing workaround.

      A commenter got qwen-code talking to OpenRouter with:

      bash
      export OPENAI_API_KEY="sk-or-v1-..."
      export OPENAI_BASE_URL="https://openrouter.ai/api/v1"
      export OPENAI_MODEL="qwen/qwen3-coder"
      

      then running qwen. For provider choice, they pointed to OpenRouter's "default provider sort" setting as a temporary workaround, not a pin. Another user said that only gives category-level choices and cannot force a named provider like Alibaba, which was a showstopper for them. A separate commenter linked a wrapper script at https://github.com/richtong/bin/blob/main/qwen.sh (opens external site) (it depends on local ./lib helpers), but it wasn't confirmed to fix anything.

      On the [API Error: OpenAI API error: Connection error.] report: with a valid key, curl to https://openrouter.ai/api/v1/chat/completions (opens external site) for qwen/qwen3-coder:free worked while qwen-code failed. The thread never diagnoses this. General advice: if curl works, re-check OPENAI_BASE_URL (must end in /api/v1), the exact model slug, and that no other env vars override these.

      Security note: the sk-or-v1-... key is a credential; keep it out of shared config files, screenshots, and git history.

      Did this work for you?
    • AgentArmorHQ teamTeam5d ago

      What a GitHub user tried on GitHub (Outcome unclear)

      Requested an OPENROUTER_PROVIDER_ORDER env var (e.g. "DeepInfra,Fireworks") in .zshrc so qwen-code would call a specific OpenRouter provider per model for cost control. No maintainer response confirmed this feature.

      Source: https://github.com/QwenLM/qwen-code/issues/70 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam5d ago

      What @tne-ops tried on GitHub (Didn't work)

      Ran qwen-code with a valid OpenRouter key and got [API Error: OpenAI API error: Connection error.], while the same key worked with curl to https://openrouter.ai/api/v1/chat/completions (opens external site) using qwen/qwen3-coder:free. No fix for this discrepancy is confirmed in the thread.

      Source: https://github.com/QwenLM/qwen-code/issues/70#issuecomment-3120848637 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam5d ago

      What @mrgoonie tried on GitHub (Worked)

      Set OPENAI_API_KEY="sk-or-v1-...", OPENAI_BASE_URL="https://openrouter.ai/api/v1", and OPENAI_MODEL="qwen/qwen3-coder". This worked for that user, and they suggested OpenRouter's default provider sort setting as a temporary routing control.

      Source: https://github.com/QwenLM/qwen-code/issues/70#issuecomment-3121582812 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam5d ago

      What @tne-ops tried on GitHub (Outcome unclear)

      Shared a shell script wrapper (https://github.com/richtong/bin/blob/main/qwen.sh (opens external site)) that depends on local ./lib helper functions. No confirmation that it resolves the connection error or provider routing.

      Source: https://github.com/QwenLM/qwen-code/issues/70#issuecomment-3123366283 (opens external site)

      Did this work for you?

    Add your answer or comment