TokenRa
中文Get API Key

Text model · Alibaba Qwen

Qwen 4 Max API

Qwen 4 Max is Alibaba Qwen's current flagship text model, available on TokenRa at 30% off the official price. It supports a 1,000,000-token context window (shared between input and output), accepts text, image, and video input, and includes a built-in thinking mode that returns reasoning in reasoning_content. Set enable_thinking: false to skip thinking. Priced at $1.34 / $4.03 / $0.095 per 1M input / output / cached tokens.

Model ID
qwen4-max
Context
1,000,000 tokens
Input
Text, image, video
Output
Text (with reasoning)
Input price
$1.34 / 1M tokens
Output price
$4.03 / 1M tokens
Cache read
$0.095 / 1M tokens
Discount
30% off official

Capabilities

Capabilities & endpoints

Chat generation through three API formats. Each was called successfully on tokenra.io on 2026-11-16; pick one to switch the code examples.

POSThttps://tokenra.io/v1/chat/completionsTested
OpenAI SDK with base_url="https://tokenra.io/v1". Auth: Authorization: Bearer. Recommended.
POSThttps://tokenra.io/v1/responsesTested
OpenAI Responses API, same SDK and key. Text answer in output_text.
POSThttps://tokenra.io/v1/messagesTested
Anthropic SDK or Claude Code with base URL https://tokenra.io. Auth: x-api-key (or Bearer) plus anthropic-version.

Request

Request parameters

Fields for POST /v1/chat/completions. Everything listed was accepted by the model in testing.

ParameterTypeRequiredDescription
modelstringYesThe model ID to call: qwen4-max.
messagesarrayYesConversation messages in order (system, user, assistant, tool). content can be a string or an array of text, image_url, or video parts.
streambooleanNoReturn the answer as server-sent events. Default false.
stream_optionsobjectNoWith {"include_usage": true}, the last chunk carries usage and an empty choices array.
max_tokensintegerNoCaps the answer text only. Reasoning tokens are not limited by it and are billed as output.
max_completion_tokensintegerNoUpper limit for all generated tokens, reasoning included. Non-thinking mode max: 131,072. Thinking mode max: 262,144.
temperaturenumberNoSampling temperature.
top_pnumberNoNucleus sampling threshold. Usually tune either this or temperature, not both.
presence_penaltynumberNoPenalises tokens that already appeared, nudging the model toward new topics.
frequency_penaltynumberNoPenalises frequent tokens to reduce repetition.
response_formatobjectNo{"type": "json_object"} returns a JSON object. {"type": "json_schema", "json_schema": {...}} returns JSON matching your schema.
toolsarrayNoFunction tools the model may call (type: "function").
tool_choicestring / objectNoauto, none, required, or a specific function.
parallel_tool_callsbooleanNoAllow several tool calls in one response.
reasoning_effortstringNolow, medium, or high. Controls reasoning depth.
enable_thinkingbooleanNoThinking is on by default. Set false to skip reasoning entirely; the answer then uses far fewer output tokens.
top_kintegerNoQwen sampling parameter: sample only from the k most likely tokens.
userstringNoYour own end-user identifier for auditing. Not part of the conversation.
Context limits by mode
  • Non-thinking mode: max input 991,808 tokens, max output 131,072 tokens.
  • Thinking mode: max input 983,616 tokens, max output 262,144 tokens (thinking content + final answer combined). Default thinking budget is 131,072 tokens; control total output length with max_completion_tokens.

Other formats

FormatRequired fieldsAnswer location
OpenAI Responsesmodel, inputoutput_text
Anthropic Messagesmodel, max_tokens, messagescontent[] blocks of type text

Response

Response format

Example response
{
  "id": "chatcmpl-1794802386001",
  "object": "chat.completion",
  "created": 1794802386,
  "model": "qwen4-max",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "An API gateway is the single entry point that receives client requests and routes them to the right backend service. It also handles shared concerns such as authentication, rate limiting and logging.",
        "reasoning_content": "The user wants two sentences about API gateways..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 26,
    "completion_tokens": 62,
    "total_tokens": 88,
    "prompt_tokens_details": { "cached_tokens": 0 },
    "completion_tokens_details": { "reasoning_tokens": 24 }
  }
}
FieldTypeDescription
idstringCompletion ID. Include it when you contact support.
objectstringchat.completion, or chat.completion.chunk when streaming.
createdintegerUnix timestamp in seconds.
modelstringThe model that produced the answer.
choices[].message.contentstringThe answer text.
choices[].message.reasoning_contentstringThe model's reasoning, returned separately from the answer.
choices[].message.tool_callsarrayTool calls requested by the model, when tools were sent.
choices[].finish_reasonstringstop, length or tool_calls.
usageobjectprompt_tokens, completion_tokens, total_tokens, plus prompt_tokens_details.cached_tokens and completion_tokens_details.reasoning_tokens.

With stream: true the answer arrives as data: lines of chat.completion.chunk objects and ends with data: [DONE].

Errors

Errors & limits

Common errors

HTTPerror.codeMeaningWhat to do
401—Missing, wrong or deleted API key.Check the Authorization: Bearer header and the key in the console.
400—The body is not valid JSON.Fix the JSON and send Content-Type: application/json.
500invalid_requestA required field is missing, for example messages.Add the field named in the message.
403insufficient_user_quotaBalance or plan quota used up.Top up in the console, then retry.
503model_not_foundUnknown model ID or no channel for your group.Check the ID against the model list.
429—Too many requests.Back off exponentially and retry.
5xx—Upstream provider failed or timed out.Retry a few times; keep the request id if it persists.

Limits and notes

  • Video input: pass the video URL as an image_url-style part with type: "video_url" in the content array.
  • Reasoning is returned in reasoning_content, separate from the answer in content. Keep it out of what you show users unless you intend to display it.
  • Minimum account top-up is $10; credits do not expire while the account is active.