Skip to content

Qwen

Call Qwen 3.8 and 3.7 models through OpenAI Chat Completions, OpenAI Responses, or Anthropic Messages.

ItemValue
Base URLhttps://api.hop-base.com/v1
ChatPOST /v1/chat/completions
ResponsesPOST /v1/responses
Anthropic MessagesPOST /v1/messages

Authenticate with a Bearer key and use the exact model ID returned by GET /v1/models. On /v1/messages, the x-api-key header also works.

curl https://api.hop-base.com/v1/chat/completions \
  -H "Authorization: Bearer sk-your-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.8-max",
    "messages": [{
      "role": "user",
      "content": "Summarize this quarter'\''s risks in five bullets."
    }]
  }'

Models

Model IDContextImage and video input
qwen3.8-max1MYes
qwen3.8-flash1MYes
qwen3.7-max1MText only
qwen3.7-plus1MYes
qwen3.7-flash1MYes

All five expose a 1,000,000-token context window and up to 131,072 output tokens per request.

All five are in the Qwen 3.8/3.7 Series (Alibaba Official) group, so one key reaches all of them. A Qwen key does not reach other families, and other families' keys do not reach Qwen. The Wan and HappyHorse video models are in the Wan 3.0 Official and HappyHorse 1.1 Official groups, each needing its own key.

Endpoint and request parameters

POST /v1/chat/completions, POST /v1/responses and POST /v1/messages all work for all five models, and streaming works normally on each. Codex CLI and other Responses-only clients connect directly; so does Claude Code, covered in Claude Code and Anthropic Messages. None of them needs CC Switch routing.

The table covers POST /v1/chat/completions. The gateway only rejects empty messages; Qwen-specific fields pass through unvalidated, and every other limit comes from the model service.

ParameterRequiredType & limitsDefaultDescription
modelRequiredOne of the five IDs above—Exact match
messagesRequiredNon-empty array; image sides must exceed 10 px—Images and video per the table above
max_tokensOptionalInteger, up to 131,072 (official limit)Service defaultCaps the output length
enable_thinkingOptionalBooleanService defaultQwen-specific, passed through
thinking_budgetOptionalIntegerService defaultCannot be combined with reasoning_effort
reasoning_effortOptionallow / high / max work as testedService defaultCannot be combined with thinking_budget
enable_searchOptionalBooleanService defaultQwen-specific, passed through
tools, tool_choiceOptionalAs in OpenAIautoRestricted in thinking mode; see below
response_formatOptionalJSON mode, as on the official APIPlain text{"type": "json_object"} returns JSON
streamOptionalBooleanfalsetrue returns server-sent events
stream_options.include_usageOptionalBooleanfalseMust be true to get usage when streaming
  • Missing or empty messages returns a gateway 400.
  • Setting both thinking_budget and reasoning_effort returns 400.
  • In thinking mode, tool_choice cannot be required or a named function; that returns 400.
  • With response_format, also ask for JSON in the prompt.
  • stream_options.include_usage does not affect billing.
  • On /v1/responses, content parts accept only input_text, input_image, and input_file: no video. Send video through Chat Completions.

For qwen3.8-max the measured input ceiling is 991,808 tokens. Above it the request returns (error text quoted from production records):

400 Range of input length should be [1, 991808]

For every parameter, see the Chat Completions API reference and pick the Qwen model family.

What the gateway changes in your request

Two rewrites are worth knowing about before you build a long-running agent on Qwen.

BehaviorEffect on your request
previous_response_idRemoved if present
storeForced to false

Requests are balanced across accounts, and an ID issued by one is not valid on another, so previous_response_id is removed. Send the full input every turn.

Claude Code and Anthropic Messages

POST /v1/messages accepts standard Anthropic Messages requests for all five models and passes them to the model's own Anthropic-compatible interface, so Claude Code and the Anthropic SDK connect directly. For the SDK, set the base URL to https://api.hop-base.com, without /v1.

With CC Switch, open the key's ··· menu in the console, select Import CCS, then Claude Code. The import fills in the model; keep the default Anthropic format, with no local routing. To set it up by hand:

export ANTHROPIC_BASE_URL="https://api.hop-base.com"
export ANTHROPIC_AUTH_TOKEN="sk-your-key"
export ANTHROPIC_MODEL="qwen3.8-max"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3.8-flash"
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=1000000
claude

Claude Code does not know these IDs, so CLAUDE_CODE_MAX_CONTEXT_TOKENS tells it the real context window; without it, Claude Code compacts the conversation at 200K tokens. More options are in Claude Code.

  • Thinking comes back in thinking blocks and counts toward output_tokens. thinking: {"type": "disabled"} turns it off.
  • qwen3.7-max is text only: a request with an image returns 400 before it reaches the model. The other four read images.
  • Forcing a tool (tool_choice set to any or to a named tool) needs thinking off. With thinking on, it returns 400 on qwen3.8-max, qwen3.8-flash and qwen3.7-plus. qwen3.7-max and qwen3.7-flash ignore a forced tool either way and may answer in text.
  • A max_tokens above 131,072 returns 400 on the three 3.7 models; the 3.8 models do not reject it.
  • cache_control breakpoints are removed before the request goes out, so explicit caching is not available; automatic prefix caching still works. In tests on 2026-10-03, Claude Code read 89%–97% of the prompt from cache from the second turn on.
  • Claude Code sends a long system prompt and tool list with every request: about 15,000 tokens before your first message, as measured. On a model with a low tier threshold, such as qwen3.7-flash, a Claude Code session crosses it early; see the next section.
400 Range of max_tokens should be [1, 131072]
400 Model qwen3.7-max does not accept image input. Remove the image from the request, including earlier turns of the conversation, or use a model that supports images.
400 The tool_choice parameter does not support being set to required or object in thinking mode

When you reconcile Anthropic Messages usage, input_tokens excludes the cached part and matches Input tokens in your usage record; cache_read_input_tokens matches Cached input tokens.

Billing and usage

Some Qwen models change tier once a request's input crosses a length threshold.

  • The threshold counts the whole prompt: cached input plus non-cached input.
  • Crossing it moves the entire request to that tier, not only the tokens past the threshold.
  • Prompt caching does not keep you under the threshold: it changes which rate applies to the cached portion, not the prompt length used for the tier.
  • The only way to stay under is to send a shorter prompt.

Which models have tiers, and where the thresholds sit, is shown in the signed-in model catalog.

completion_tokens already includes reasoning tokens, so do not add them again. completion_tokens_details.reasoning_tokens is a subset of the output, reported for visibility only.

Your HopBase usage record and the response body count input differently, which matters when you reconcile:

FieldMeaning
Response prompt_tokensWhole prompt, cached portion included
Usage record Input tokensPrompt minus the cached portion
Usage record Cached input tokensThe cached portion, listed separately

So the usage record's input plus cached input equals the response's prompt_tokens.

Error handling

The model's own 4xx responses are passed through with vendor-specific error-code prefixes stripped, so the message text is human-readable but not stable. Branch on the HTTP status and the code field, never on the message string.

A model name that is not in your group returns 404 model_not_found. Model IDs are exact; read them from GET /v1/models rather than guessing.

Next steps