Qwen3.8 Max API: Key Setup, Endpoint, Model ID, Python
Set up a Qwen3.8 Max API key with OurToken's OpenAI-compatible endpoint. Use the qwen3.8-max model ID, test with cURL, and call the API from Python.

A Qwen3.8 Max API key is only useful when the credential, endpoint, model ID, and request body all point at the same route. Qwen3.8 Max is the flagship model of the Qwen 3.8 family: a multimodal, 1M-context route for chat, coding, reasoning, long-context work, and production assistant workloads. The key, the base URL, and the model ID must match, or the request fails even though each value looks valid on its own.
This guide walks through a Qwen3.8 Max API setup through OurToken: where to create the key, the exact endpoint and model ID, a cURL smoke test, a Python example using the OpenAI SDK, usage accounting, and the differences between Qwen3.8 Max and the Qwen 3.7 routes you may already be calling. The route used here is:
https://api.ourtoken.ai/v1/chat/completions
Verification status: This article is documentation-verified against the public OurToken Qwen3.8 Max page, the OurToken Qwen3.8 Flash page, and the official Alibaba Cloud Model Studio qwen3.8-max page, all checked on 2026-10-10. Prices and model IDs can change; confirm the live model page before committing to a budget.
Qwen3.8 Max API Setup at a Glance
For the primary example, use the Qwen3.8 Max route on OurToken. Keep these values in configuration rather than scattering them across application code.
| Setting | OurToken value | Why it matters |
|---|---|---|
| API key | OURTOKEN_API_KEY | Authenticates the request |
| SDK base URL | https://api.ourtoken.ai/v1 | The URL passed to an OpenAI-compatible client |
| Full API endpoint | https://api.ourtoken.ai/v1/chat/completions | The URL used by cURL or a raw HTTP client |
| Model ID | qwen3.8-max | Selects the Qwen3.8 Max route |
| Required body fields | model, messages | Identifies the model and conversation |
| Context window | 1M tokens | Matches the official Qwen3.8 Max specification |
The distinction between the SDK base URL and the full endpoint is easy to miss. An OpenAI-compatible Python client appends /chat/completions for the chat method, so its base_url should end at /v1. A raw cURL request does not append anything; it should use the complete /v1/chat/completions URL.
Max and Flash model IDs
OurToken exposes two Qwen3.8 routes that suit different workloads:
| Route | Model ID | Typical starting point |
|---|---|---|
| Qwen3.8 Max | qwen3.8-max | Chat, coding, reasoning, multimodal understanding, production assistant workloads |
| Qwen3.8 Flash | qwen3.8-flash | Near-flagship quality at a lower price, high-volume and cost-sensitive workloads |
These are model IDs, not website slugs. Do not copy a catalog path such as qwen/qwen3.8-max into the JSON model field. For this article, every request uses the exact OurToken value qwen3.8-max.
Both routes use the OpenAI-compatible Chat Completions shape through OurToken, so a client that already talks to GPT or DeepSeek routes on OurToken can switch models without changing transport.
Get and Test a Qwen3.8 Max API Key
An API key authenticates programmatic access. For the OurToken route, open the OurToken API Keys page, create or select a key, and keep it server-side. Use an environment variable during local development:
On macOS or Linux:
export OURTOKEN_API_KEY="paste-your-key-locally"
On Windows PowerShell:
$env:OURTOKEN_API_KEY = "paste-your-key-locally"
The HTTP request sends the secret in the standard header:
Authorization: Bearer YOUR_API_KEY
Do not put the key in frontend JavaScript, a mobile app bundle, a public Git repository, or a blog post. Logs should record a request ID, status code, model ID, latency, and redacted usage data rather than the authorization header.
cURL smoke test
The following is a minimal non-streaming request through OurToken, using the full endpoint:
curl -sS https://api.ourtoken.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${OURTOKEN_API_KEY}" \
-d '{
"model": "qwen3.8-max",
"messages": [
{
"role": "user",
"content": "Give me a three-step checklist for reviewing a schema migration."
}
],
"max_tokens": 256
}'
Once this succeeds, add one change at a time: temperature, stream, tools, or a structured response format. If a new field causes a 400 response, remove that field and compare it with the current OurToken model reference instead of assuming every field from the official Qwen API is supported by every compatibility layer.
What a successful response should contain.
For a non-streaming Chat Completions response, inspect the structural fields:
{
"id": "chatcmpl-redacted",
"object": "chat.completion",
"model": "qwen3.8-max",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "1. Review the schema changes.\n2. Test rollback.\n3. Validate production impact."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 30,
"completion_tokens": 24,
"total_tokens": 54
}
}
This is an illustrative response shape, not a live response captured from an OurToken account. When cache details are returned, prompt_tokens_details.cached_tokens is a breakdown of the input total; do not add cached tokens on top of the full prompt count when estimating cost.
Common cURL mistakes.
| Symptom | Likely cause | Fix |
|---|---|---|
401 Unauthorized | Missing, expired, or wrong-provider key | Check OURTOKEN_API_KEY and use the OurToken key with the OurToken URL |
404 Not Found | Wrong path or model value | Use /v1/chat/completions and qwen3.8-max |
400 for an invalid body | Malformed JSON or missing messages | Validate the JSON and send an array of role/content messages |
400 after adding an option | The route does not accept that optional field | Remove it, then verify support on the live model page |
429 Too Many Requests | Rate limit or account capacity | Slow down, use bounded backoff, and avoid unlimited retries |
Do not retry a 400, 401, or 404 unchanged. Those responses indicate a configuration or request problem, not a transient provider failure.
Qwen3.8 Max Python API Usage
The official OpenAI Python library can be configured with a compatible base URL:
python -m pip install --upgrade openai
Then create a client with the OurToken base URL. The base URL ends at /v1; the SDK adds the Chat Completions operation when you call client.chat.completions.create.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["OURTOKEN_API_KEY"],
base_url="https://api.ourtoken.ai/v1",
)
response = client.chat.completions.create(
model="qwen3.8-max",
messages=[
{
"role": "system",
"content": "You are a concise software engineering assistant.",
},
{
"role": "user",
"content": "List the checks for a safe schema migration.",
},
],
max_tokens=256,
)
print(response.choices[0].message.content)
if response.usage:
usage = response.usage
cached_details = getattr(usage, "prompt_tokens_details", None)
print(
{
"prompt_tokens": usage.prompt_tokens,
"completion_tokens": usage.completion_tokens,
"total_tokens": usage.total_tokens,
"cached_tokens": getattr(cached_details, "cached_tokens", 0),
}
)
Keep the first Python request deterministic. For a smoke test, keep the input short and the output cap low. The following checks are more useful than simply printing a successful string:
assert response.model == "qwen3.8-max"
assert response.choices
assert response.choices[0].message.role == "assistant"
assert response.choices[0].message.content is not None
In an application, replace assertions with structured error handling and telemetry. The test should fail loudly if a gateway returns a different model or an empty message.
Qwen3.8 Max vs Qwen 3.7: What Changed
If you already call Qwen 3.7 routes on OurToken (the Qwen API key setup guide covers that family), the move to Qwen3.8 Max is a model ID change plus a few capability upgrades.
| Capability | Qwen3.8 Max | Notes |
|---|---|---|
| Context window | 1M tokens | Same headline spec as the official qwen3.8-max snapshot |
| Multimodal input | Image, text, video | The official page lists image/text/video input and text output |
| Function calling | Supported | Test tool calling on the live route before relying on it; the OpenAI-compatible tool calling guide covers cross-model consistency |
| Structured output | Supported | Useful for extraction and agent workflows |
| Web search, prefix continuation, context caching | Supported | Cache billing is a subset of input, not an extra full charge |
| Batch inference | Supported | The official route also supports batch; combine with the OpenAI batch API guide if you need the async pattern |
The official Alibaba Cloud page lists the snapshot qwen3.8-max-0902 (alias qwen3.8-max-2026-09-02) with a 1M context window, a max input length of 991,808 tokens, and a max output length of 131,072 tokens. Treat those as the underlying model specification; the route-level limits are whatever the live OurToken page shows.
If your workload is chat-heavy, high-volume, or cost-sensitive rather than at the quality frontier, Qwen3.8 Flash is the cheaper sibling: it carries the same 1M context and near-flagship quality at roughly a tenth of the Max input price. The right default for many applications is Flash, with Max reserved for the tasks that actually need the frontier model. The LLM model routing guide is the playbook for splitting those two classes of traffic instead of sending everything to the most expensive route.
Qwen3.8 Max API Pricing on OurToken
OurToken lists its Qwen3.8 routes at 60% of the official reference price. The current per-million-token rates are:
| Route | Input | Output | Cached input | Cache writes |
|---|---|---|---|---|
Qwen3.8 Max (qwen3.8-max) | $1.2000 / 1M | $3.6000 / 1M | $0.1500 / 1M | $1.5000 / 1M |
Qwen3.8 Flash (qwen3.8-flash) | $0.0900 / 1M | $0.2820 / 1M | $0.0096 / 1M | $0.1200 / 1M |
For 100,000 input tokens and 20,000 output tokens on Max:
Input: 100,000 / 1,000,000 * $1.2000 = $0.12000
Output: 20,000 / 1,000,000 * $3.6000 = $0.07200
Total: = $0.19200
For a repeated-context request with 80,000 cached input tokens and 20,000 uncached input tokens on Max, the input side is:
Cached input: 80,000 / 1,000,000 * $0.1500 = $0.01200
Uncached input: 20,000 / 1,000,000 * $1.2000 = $0.02400
Input total: = $0.03600
The second calculation assumes the route reports cached tokens in prompt_tokens_details and bills them at the cached-input rate. The official OpenAI-compatible prompt caching guide covers the accounting rule: cached tokens are a subset of input tokens, so never count the full prompt price and the cached price for the same tokens.
Prices change. The official Alibaba Cloud reference (¥12 / ¥36 per million tokens for Max input/output in the mainland region) differs from the USD reference OurToken shows on the model page; use the live OurToken page as the source of truth for billing, and re-check it when you set a quarterly budget.
From a Smoke Test to a Production Integration
A first response proves only that one request passed. A production integration also needs secret management, a model allowlist, and a clear fallback.
Request architecture. Keep the API key on a server or trusted worker. A browser should call your application backend, not expose the OurToken credential directly:
User or internal service
|
| application request
v
Your backend / job worker
|
| Authorization: Bearer OURTOKEN_API_KEY
v
https://api.ourtoken.ai/v1/chat/completions
|
| model = qwen3.8-max
v
Qwen3.8 Max route
|
v
Assistant response + usage data
|
v
Redacted logs, budget checks, and application output
Model allowlist. The backend should own the model mapping. Do not accept an arbitrary model string from an untrusted client and pass it directly to the gateway:
MODEL_IDS = {
"quality": "qwen3.8-max",
"economy": "qwen3.8-flash",
}
def resolve_model(name: str) -> str:
try:
return MODEL_IDS[name]
except KeyError as exc:
raise ValueError("Unsupported model selection") from exc
Release checklist. Before using a Qwen3.8 Max API key with real users:
- The key is available only to a server process or protected worker.
- cURL succeeds against
https://api.ourtoken.ai/v1/chat/completions. - The request uses
qwen3.8-max, not a website slug or display label. - The Python SDK uses
base_url="https://api.ourtoken.ai/v1". - The response model and choice role are validated.
- Usage records use
prompt_tokens,completion_tokens, andtotal_tokens. - Cached tokens are not counted twice in cost calculations.
- 400, 401, 404, 429, timeout, and 5xx behavior is tested.
- Optional tools, streaming, or structured output are enabled one at a time and verified on the live model route.
Conclusion
The reliable Qwen3.8 Max API setup is compact: create an OurToken key, set https://api.ourtoken.ai/v1 as the SDK base URL, call /chat/completions, and send the exact qwen3.8-max model ID. Start with the short cURL request, repeat it in Python, inspect the response usage, and only then add multimodal inputs, tools, streaming, or larger prompts.
When you are ready to test the integration with a real credential, review the Qwen3.8 Max API configuration and create a key through the OurToken API Keys page. If your workload is volume- and cost-sensitive rather than frontier-quality-driven, evaluate Qwen3.8 Flash on the same endpoint before defaulting to Max.
FAQ
What is the Qwen3.8 Max API endpoint on OurToken?
The full endpoint is https://api.ourtoken.ai/v1/chat/completions. For the OpenAI Python SDK, set base_url to https://api.ourtoken.ai/v1 and call client.chat.completions.create.
What is the Qwen3.8 Max model ID?
Use qwen3.8-max on OurToken. Do not send qwen/qwen3.8-max as the API model value.
What is the Qwen3.8 Max price on OurToken?
As of 2026-10-10, $1.2000 / 1M input, $3.6000 / 1M output, $0.1500 / 1M cached input, and $1.5000 / 1M cache writes, listed at 60% of the official reference. Confirm the live model page before budgeting.
Can I use the OpenAI Python SDK for Qwen3.8 Max?
Yes. Install the openai package, set the OurToken base URL, read the key from OURTOKEN_API_KEY, and call the Chat Completions method with model="qwen3.8-max".
Should I use Qwen3.8 Max or Flash?
Use Max when frontier-quality chat, coding, reasoning, or multimodal understanding is the priority. Use Flash for high-volume, cost-sensitive workloads; it keeps the 1M context at roughly a tenth of the Max input price.
Does Qwen3.8 Max support multimodal input?
The official specification lists image, text, and video input with text output. Test the route's actual support on the live OurToken model page before enabling multimodal fields in production.