Qwen
Call Qwen 3.8 and 3.7 models through OpenAI Chat Completions, OpenAI Responses, or Anthropic Messages.
| Item | Value |
|---|---|
| Base URL | https://api.hop-base.com/v1 |
| Chat | POST /v1/chat/completions |
| Responses | POST /v1/responses |
| Anthropic Messages | POST /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 ID | Context | Image and video input |
|---|---|---|
qwen3.8-max | 1M | Yes |
qwen3.8-flash | 1M | Yes |
qwen3.7-max | 1M | Text only |
qwen3.7-plus | 1M | Yes |
qwen3.7-flash | 1M | Yes |
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.
| Parameter | Required | Type & limits | Default | Description |
|---|---|---|---|---|
model | Required | One of the five IDs above | — | Exact match |
messages | Required | Non-empty array; image sides must exceed 10 px | — | Images and video per the table above |
max_tokens | Optional | Integer, up to 131,072 (official limit) | Service default | Caps the output length |
enable_thinking | Optional | Boolean | Service default | Qwen-specific, passed through |
thinking_budget | Optional | Integer | Service default | Cannot be combined with reasoning_effort |
reasoning_effort | Optional | low / high / max work as tested | Service default | Cannot be combined with thinking_budget |
enable_search | Optional | Boolean | Service default | Qwen-specific, passed through |
tools, tool_choice | Optional | As in OpenAI | auto | Restricted in thinking mode; see below |
response_format | Optional | JSON mode, as on the official API | Plain text | {"type": "json_object"} returns JSON |
stream | Optional | Boolean | false | true returns server-sent events |
stream_options.include_usage | Optional | Boolean | false | Must be true to get usage when streaming |
- Missing or empty
messagesreturns a gateway 400. - Setting both
thinking_budgetandreasoning_effortreturns 400. - In thinking mode,
tool_choicecannot berequiredor a named function; that returns 400. - With
response_format, also ask for JSON in the prompt. stream_options.include_usagedoes not affect billing.- On
/v1/responses, content parts accept onlyinput_text,input_image, andinput_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.
| Behavior | Effect on your request |
|---|---|
previous_response_id | Removed if present |
store | Forced 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
claudeClaude 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
thinkingblocks and counts towardoutput_tokens.thinking: {"type": "disabled"}turns it off. qwen3.7-maxis text only: a request with an image returns400before it reaches the model. The other four read images.- Forcing a tool (
tool_choiceset toanyor to a named tool) needs thinking off. With thinking on, it returns400onqwen3.8-max,qwen3.8-flashandqwen3.7-plus.qwen3.7-maxandqwen3.7-flashignore a forced tool either way and may answer in text. - A
max_tokensabove 131,072 returns400on the three 3.7 models; the 3.8 models do not reject it. cache_controlbreakpoints 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 modeWhen 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:
| Field | Meaning |
|---|---|
Response prompt_tokens | Whole prompt, cached portion included |
| Usage record Input tokens | Prompt minus the cached portion |
| Usage record Cached input tokens | The 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
- OpenAI SDK — the general Chat Completions pattern
- Codex CLI — direct connection over Responses
- Claude Code — direct connection over Anthropic Messages
- Error codes and retries
- Concurrency, timeouts, and billing