Skip to content
StartQwen API

Qwen API

Seven Qwen models through Messages, Chat Completions, and Responses: requests, pricing, queue, search, tools, and images.

Qwen uses the same gd-… key and shared Guard balance. Seven models are available for generation; their exact IDs, input, context, and prices are listed below.

Get a key from @subscribe_ai_bot, then choose HTTP, the Python SDK, or the Node.js SDK. One shared key is issued; no separate Qwen account is required.

Quick start

  1. Save the key in GUARD_API_KEY; do not commit it or print it to logs.
  2. Choose Messages, Chat Completions, or Responses. Each is available under shared /v1 and family /qwen/v1 paths.
  3. Send an exact model and an output budget of 4096. Use a regular JSON response for the first request.
  4. Check the text, terminal state, and usage; then enable stream: true if needed.
bash
export GUARD_API_KEY="gd-your-key"
curl https://api.guardrelay.ai/qwen/v1/messages \
  -H "Authorization: Bearer $GUARD_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"qwen3.7-plus","max_tokens":4096,"messages":[{"role":"user","content":"Reply with OK"}]}'
powershell
$env:GUARD_API_KEY = "gd-your-key"
$headers = @{
  Authorization = "Bearer $env:GUARD_API_KEY"
  "anthropic-version" = "2023-06-01"
}
$body = @{
  model = "qwen3.7-plus"
  max_tokens = 4096
  messages = @(@{ role = "user"; content = "Reply with OK" })
} | ConvertTo-Json -Depth 10
Invoke-RestMethod -Method Post `
  -Uri "https://api.guardrelay.ai/qwen/v1/messages" `
  -Headers $headers `
  -ContentType "application/json" `
  -Body $body

Two namespaces, three APIs

APIShared pathQwen pathOutput budget
MessagesPOST /v1/messagesPOST /qwen/v1/messagesmax_tokens
Chat CompletionsPOST /v1/chat/completionsPOST /qwen/v1/chat/completionsmax_tokens / max_completion_tokens
ResponsesPOST /v1/responsesPOST /qwen/v1/responsesmax_output_tokens

Both namespaces expose the same Qwen contract and billing. The family URL is convenient for a dedicated client profile and accepts only Qwen models; the shared URL is convenient when an application already selects the family through model.

Models, input, and context

Model IDInputContextOutput limit
qwen3.8-maxText and images1,000,000131,072
qwen3.7-maxText only1,000,000131,072
qwen3.7-plusText and images1,000,00065,536
qwen3.6-plusText and images1,000,00065,536
qwen3.5-plusText and images1,000,00065,536
qwen3.5-omni-plusText and images262,144, input up to 196,60865,536
qwen3.8-omni-flashText and images1,000,000131,072

JSON responses and SSE

APIJSON terminalSSE terminalUsage
Messagesstop_reason: end_turn, max_tokens, tool_usemessage_delta → message_stopinput_tokens, output_tokens
Chat Completionschoices[].finish_reason: stop, length, tool_callsfinal chunk + [DONE]prompt_tokens, completion_tokens, total_tokens
Responsesstatus: completed, incompleteresponse.completedinput_tokens, output_tokens, total_tokens

Pricing

ModelRequest input, tokensInput / 1MOutput / 1M
qwen3.8-maxup to 1,000,000$2.00$6.00
qwen3.7-maxup to 1,000,000$2.50$7.50
qwen3.7-plusup to 256,000$0.40$1.60
qwen3.7-plusabove 256,000$1.20$4.80
qwen3.6-plusup to 256,000$0.50$3.00
qwen3.6-plusabove 256,000$2.00$6.00
qwen3.5-plusup to 256,000$0.40$2.40
qwen3.5-plusabove 256,000$0.50$3.00
qwen3.5-omni-plusup to 196,608$1.40$8.30
qwen3.8-omni-flashup to 1,000,000$0.15$0.47

Rates equal Alibaba Cloud's official rates for these models, with multiplier 1, including PRIVATE. The Plus models have two tiers: if request input exceeds 256,000 tokens, the whole request, both input and output, uses the second row. If the model searched the web at least once, the request costs $0.01 more; the number of searches does not change the price. Qwen has no cache.

For qwen3.7-plus, 10,000 input and 2,000 output tokens cost 10000×0.40/1M + 2000×1.60/1M = $0.00720000; if the model searched the web, $0.01720000 for any number of searches. At 300,000 input and 2,000 output tokens, the second tier applies: 300000×1.20/1M + 2000×4.80/1M = $0.36960000.

Free input counting

bash
curl https://api.guardrelay.ai/qwen/v1/messages/count_tokens \
  -H "Authorization: Bearer $GUARD_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"qwen3.7-plus","messages":[{"role":"user","content":"Count this input"}]}'

The gateway counts locally, without calling the model and without a charge. It returns the same input estimate that generation billing uses, plus the X-Guard-Usage-Source: estimated header.

Sessions, queue, and model fallback

  • One Qwen account serves one client session and runs one request at a time. Parallel requests in one session wait for each other.
  • A new session of the same key, for example after /clear, gets the account as soon as the account finishes the current request. Requests from other keys wait for a free account.
  • If no account is free, a request waits in the queue for up to 30 seconds and then receives 429 queue_timeout with Retry-After: 30.
  • Generating one answer takes at most 10 minutes; longer generation fails with generation_timeout.
  • After 10 minutes without requests, the account is released. The next message continues the conversation from the history the client sends.

If the requested model is busy at the provider or its limit is exhausted, the nearest free Qwen model that accepts the request answers instead. The fallback happens before the first character of the answer. The client sees the requested model in the response and pays its rate. If no suitable model is free, the response is 429 provider_at_capacity with Retry-After: 5; if Qwen is temporarily unavailable, 503 qwen_unavailable with Retry-After: 30.

In the dashboard, Qwen can be paused and given its own hourly and daily spending limits for the key. A pause returns 403 api_key_paused; a reached limit returns 429 customer_hour_limit or 429 customer_day_limit.

Client functions and web search are separate mechanisms. Your application executes a function and returns its result to the model. Qwen runs web search itself when it decides search is needed; there is no separate parameter to enable or forbid it. If the model searched at least once, Guard adds $0.01 to the request once, however many searches it made.

APIClient function declaration
Chat Completions{type: "function", function: {name, description, parameters}}
Messages{name, description, input_schema}
Responses{type: "function", name, description, parameters}

Where to go next

MessagesBody, usage, stop_reason, tools, and SSE.Chat CompletionsOpenAI-compatible request, tools, and images.ResponsesFull history in input and the incomplete terminal.Qwen errorsCodes, queue, retries, and client actions.Python SDKShort examples for the OpenAI and Anthropic SDKs.Node.js SDKChat Completions and Responses without hidden retries.

Documentation sections

On this page