TokenFab Docs Center
A large LLM inference service platform, compatible with OpenAI SDK to help developers quickly build AI applications.
from openai import OpenAI
client = OpenAI(
api_key="your-api-key",
base_url="https://api.tokenfab.cn/v1"
)
resp = client.chat.completions.create(
model="glm-5.2",
messages=[{"role": "user", "content": "hello, TokenFab"}]
)
print(resp.choices[0].message.content)Platform Capabilities
Quick Navigation
Questions? See the FAQ or Contact Us.
Get API Key
Follow these steps to create an API key and start calling the TokenFab API.
1Create API Key
- Visit TokenFab Console,log in or register.
- Go to Console → API Keys.
- Click "Create API Key", enter a note, then confirm.
- Copy the key (format:
tk-xxxx...), it cannot be viewed again after closing.
⚠️ Warning
Keep your API Key secure. Do not commit it to version control or hardcode it in frontend code.
2Configure Environment Variables
Linux / macOS (Bash)
export TOKENFAB_API_KEY="your-api-key"Windows (PowerShell)
$env:TOKENFAB_API_KEY="your-api-key"The api_key in later examples can be replaced with your key directly; if you use the environment variable above, read TOKENFAB_API_KEY in your code.
First API Call
Use the Python SDK to make your first API call.
Install Dependencies
pip install openaiCall Example
from openai import OpenAI
client = OpenAI(api_key="your-api-key", base_url="https://api.tokenfab.cn/v1")
resp = client.chat.completions.create(model="glm-5.2", messages=[{"role":"user","content":"Introduce the TokenFab platform"}])
print(resp.choices[0].message.content)SDK Guide
TokenFab API is compatible with the OpenAI SDK.
Install
pip install openaiInitialize
from openai import OpenAI
client = OpenAI(api_key="your-api-key", base_url="https://api.tokenfab.cn/v1")Error Handling
try:
r = client.chat.completions.create(model="glm-5.2", messages=[{"role":"user","content":"Hello"}])
except Exception as e:
print(f"Error: {e}")OpenAI SDK Compatibility
TokenFab provides an OpenAI-compatible interface. Basic Chat Completions calls require only two changes to migrate; configure extensions such as Thinking Mode and Web Search according to this guide.
| Config Field | OpenAI | TokenFab |
|---|---|---|
| api_key | sk-xxx... | tk-xxxx... |
| base_url | https://api.openai.com/v1 | https://api.tokenfab.cn/v1 |
💡 Tip
OpenAI-compatible features can be used directly; for TokenFab extensions such as Thinking Mode and Web Search, follow the corresponding sections.
Responses API access
The same base_url also speaks the OpenAI Responses protocol (client.responses.create). Built-in tools are exclusive to this protocol; auth and billing are identical to Chat Completions:
from openai import OpenAI
client = OpenAI(base_url="https://api.tokenfab.cn/v1", api_key="your-api-key")
resp = client.responses.create(
model="glm-5.2",
input="Hello, TokenFab",
instructions="Answer in English.")
print(resp.output_text)Anthropic SDK Compatibility
TokenFab API is compatible with the Anthropic SDK (Messages API). Simply modify the base_url to migrate your existing Anthropic applications to TokenFab.
⚠️ Tip
Anthropic protocol currently supports the following models: glm-5.2, qwen3.7-max, qwen3.7-plus, kimi-k3
Migration Guide
Update the following two required configuration items; set the optional ANTHROPIC_AUTH_TOKEN only if your client requires it:
| Environment Variable | Description | TokenFab Configuration Value |
|---|---|---|
ANTHROPIC_API_KEY | API Key | tk-xxxx... |
ANTHROPIC_BASE_URL | Compatible endpoint URL | https://api.tokenfab.cn/anthropic |
ANTHROPIC_AUTH_TOKEN | Auth token (optional, equivalent to API_KEY) | tk-xxxx... |
Quick Start
Text Chat
import anthropic
client = anthropic.Anthropic(
api_key="your-api-key",
base_url="https://api.tokenfab.cn/anthropic",
)
message = client.messages.create(
model="glm-5.2",
max_tokens=1024,
messages=[{"role": "user", "content": "hello"}],
thinking={"type": "disabled"},
)
print(message.content[0].text)Streaming Output
with client.messages.stream(
model="glm-5.2",
max_tokens=1024,
messages=[{"role": "user", "content": "Tell me a story"}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)Integrating Agent Tools
TokenFab API is compatible with the OpenAI interface format and can easily integrate with various AI coding assistants, Agent frameworks, and IDE plugins. Select the tool you are using and follow the configuration guide.
Integrate Claude Code
AI coding assistant running in your terminal, point it to TokenFab via config file
Integrate OpenClaw
Open-source personal AI assistant, integrates with chat tools like Feishu and WeChat, extends capabilities through Skills
Integrate Hermes
Nous Research open-source self-evolving AI Agent with built-in learning loop and skill accumulation
Integrate WorkBuddy
AI Agent and coding assistant, supports custom model config files, integrates via OpenAI Compatibility API
Integrate Claude Code
Claude Code is an AI coding assistant that runs in your terminal. By replacing the model in the configuration file, you can point Claude Code to the TokenFab API and use our models for an advanced coding experience.
Migrate from Existing Installation
If you have already installed Claude Code, follow these steps to complete the configuration:
Linux / Mac
export ANTHROPIC_BASE_URL="https://api.tokenfab.cn/anthropic"
export ANTHROPIC_AUTH_TOKEN="your-api-key"
export ANTHROPIC_DEFAULT_MODEL="glm-5.2"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="glm-5.2"
export ANTHROPIC_SMALL_FAST_MODEL="glm-5.2"
export CLAUDE_CODE_DEFAULT_HAIKU_MODEL="glm-5.2"
export CLAUDE_CODE_SUBAGENT_MODEL="glm-5.2"Windows (PowerShell)
$env:ANTHROPIC_BASE_URL="https://api.tokenfab.cn/anthropic"
$env:ANTHROPIC_AUTH_TOKEN="your-api-key"
$env:ANTHROPIC_DEFAULT_MODEL="glm-5.2"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL="glm-5.2"
$env:ANTHROPIC_SMALL_FAST_MODEL="glm-5.2"
$env:CLAUDE_CODE_DEFAULT_HAIKU_MODEL="glm-5.2"
$env:CLAUDE_CODE_SUBAGENT_MODEL="glm-5.2"Tip
The "Migrate from Existing Installation" section above contains the configuration variables. Get the API Key from the console.
After configuration, run claude --version to verify the version. If the version displays correctly, you can proceed with the next steps.
Getting Started
cd /path/to/my-project
claudeWeb Search Feature
TokenFab API supports the Claude Code Web Search feature. When the model determines your question needs searching, it returns search results with citations. Since different models have different Web Search usage, you can refer to the official Claude Code documentation.
Model Mapping
With Claude Code, we can automatically map incoming Claude model names:
| Claude Models | Maps To |
|---|---|
claude-opus-4 / claude-opus-4-1 | glm-5.2 |
claude-sonnet-4 / claude-haiku-4 | glm-5.2 |
By modifying ~/.claude/settings.json to customize the imported Claude models for automatic mapping.
Integrate OpenClaw
OpenClaw is an open-source personal AI assistant that integrates with chat tools like Feishu and WeChat, and extends capabilities through Skills. With simple configuration, you can point OpenClaw to the TokenFab API.
Migrate from Existing Installation
If you have already installed OpenClaw, run the following command to re-enter the configuration phase and switch to the TokenFab provider:
openclaw onboard --install-daemonThen follow the prompts:
- When you see I understand this is personally-by-default... select Yes
- When you see Skip onboarding by default? select No to continue configuration
Install OpenClaw
Linux / Mac
curl -fsSL https://openclaw.ai/install.sh | bashWindows (PowerShell)
iwr -useb https://openclaw.ai/install.ps1 | iexConfigure Default Model
After first installation, it will automatically enter the configuration phase; existing users can run openclaw onboard --install-daemon to enter the configuration phase.
- When you see I understand this is personally-by-default... select Yes
- Select Setup node recommended: QuickStart
- When you see ModelAuth provider select TokenFab
- When you see Enter API key:Enter your TokenFab API Key
- When you see Default model:enter the model name(glm-5.2)
- When you see Skip permissions for... configure as needed; beginners can choose Skip for now
Getting Started
Open Web UI
openclaw dashboardChat in terminal
openclaw terminalChat with a specific model
openclaw terminal --model glm-5.2Integrate Hermes
Hermes is an open-source self-evolving AI Agent built by Nous Research. It has a built-in learning loop that generates skills from experience, continuously optimizes during use, accumulates knowledge, and gradually builds a dynamic model around your preferred topics.
Install Hermes
Quick Install
With a single install command, you can launch the Hermes Agent in under two minutes.
Linux / macOS / WSL2
curl -fsSL https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh | bashThe only dependency is Git. The command clones the Hermes repository from GitHub and provides a ready-to-use set of scripts and commands.
Quick Start
- Run
hermes setup - Select Quick Setup
- When prompted to select a model provider, choose TokenFab
- Enter your TokenFab API Key
- Base URL::
https://api.tokenfab.cn/v1 - Select glm-5.2 Models
- Continue with the remaining configuration options
Integrate WorkBuddy
WorkBuddy / CodeBuddy is an AI Agent and coding assistant tool. It supports adding custom models through local model configuration files and can connect to TokenFab using the OpenAI-compatible Chat Completions API.
Configure Model
In the WorkBuddy model configuration file, add the following JSON config. The API Key is obtained from the console. Replace ${{API_KEY}} with your actual TokenFab API Key; do not leave the placeholder in the config.
{
"models": [
{
"id": "deepseek-v4-pro",
"name": "DeepSeek V4 Pro",
"vendor": "TokenFab",
"url": "https://api.tokenfab.cn/v1/chat/completions",
"apiKey": "${{API_KEY}}",
"maxInputTokens": 128000,
"maxOutputTokens": 8192,
"supportsToolCall": true,
"supportsImages": false,
"relatedModels": {
"lite": "deepseek-v4-flash",
"reasoning": "deepseek-v4-pro"
}
},
{
"id": "deepseek-v4-flash",
"name": "DeepSeek V4 Flash",
"vendor": "TokenFab",
"url": "https://api.tokenfab.cn/v1/chat/completions",
"apiKey": "${{API_KEY}}",
"maxInputTokens": 128000,
"maxOutputTokens": 8192,
"supportsToolCall": true,
"supportsImages": false
}
],
"availableModels": [
"deepseek-v4-pro",
"deepseek-v4-flash"
]
}💡 Tip
The url in the config uses the OpenAI-compatible Chat Completions endpoint. Make sure apiKey contains your actual TokenFab API Key and that the placeholder is removed.
Voucher Usage Guide
View, use, and manage your vouchers
What Is a Voucher
A voucher is a monetary benefit granted by TokenFab in the form of a virtual coupon, which can be used to offset the fees you incur from using our products. A voucher has a fixed face value and can be applied multiple times within its remaining balance, until the balance is used up or the voucher expires.
Viewing Vouchers
Sign in to TokenFab Console, go to Billing > Voucher Management, and you can view all vouchers in your account.
The list page provides the following filters to help you quickly locate a voucher:
- Effective period: filter by the voucher's effective time range
- Keyword search: search by voucher name or ID
- Status filter: filter vouchers that are available, used up, expired, or voided
The voucher attributes are as follows:
| Attribute | Description |
|---|---|
| Voucher ID | The unique identifier of the voucher |
| Face value | The face value of the voucher |
| Balance | The remaining deductible amount of the voucher |
| Applicable products | The product scope eligible for voucher deduction, e.g. all products or specific products |
| Payment method | The payment methods eligible for voucher deduction, e.g. pay-as-you-go |
| Validity period | The valid usage period of the voucher |
| Granted at | The time when the voucher was credited to your account |
| Status | Available, used up, expired, or voided |
Click View Details in the actions column of the list to go to the voucher details page and view the complete information of the voucher (summary, applicable products, deduction records).
How to Use Vouchers
A voucher comes with usage conditions such as the applicable product scope, eligible payment methods, and a valid usage period. For details, see the voucher details page.
Deduction Rules
- Automatic matching: the system prioritizes vouchers that are expiring soon.
- Multiple vouchers: if the balance of a single voucher is not enough to cover the entire bill, the system automatically applies the next available voucher and continues deducting until the bill is fully covered or all available vouchers are used up.
- Balance payment: if any amount remains on the bill after voucher deductions, the remaining amount must be paid with your account balance.
Deduction Scope and Limitations
- Product scope: only model invocation fees within the voucher's applicable product scope are deductible. When the applicable products are set to all products, any pay-as-you-go product can be deducted; when set to specific products, only the fees of the corresponding products are deductible. The voucher details page shall prevail.
- No deduction of outstanding payments: vouchers cannot be used to cover historical overdue charges. Overdue charges must be paid off by topping up your account.
Viewing Deduction Details
In the Voucher Management list, click View Details to go to the voucher details page. Under "Usage Details", you can view all deduction records of the voucher, including the deduction record ID, deduction time, and deduction amount.
Usage Details supports filtering by time and transaction type, and can be exported for reconciliation.
Validity Rules
Voucher validity periods come in two types, as shown on the voucher details page:
- Fixed period: the voucher is valid between the specified effective date and expiration date.
- N days after grant: starts counting N days from the date the voucher is credited to your account, and expires automatically when due.
FAQ
Why hasn't my voucher been deducted from my bill?
Common reasons include:
- Product restrictions: the product consumed in this billing cycle is not within the voucher's applicable product scope
- Expired: the bill issuance time is past the voucher's validity period
- Insufficient balance: the voucher is used up, so the system automatically uses another available voucher or your account balance
- Voided: the voucher has been voided by our operations team and its balance has been cleared
- Overdue status: when your account has overdue charges, vouchers cannot cover the overdue portion
- Bill not yet issued: pay-as-you-go bills may take time to settle. Please check back later
If the cause still cannot be identified, verify the applicable products and validity period on the voucher details page, or contact customer support with the voucher ID (e.g. VF15474540) for troubleshooting.
Can vouchers be cashed out, withdrawn, or transferred to the account balance?
No. Vouchers cannot be converted to cash, topped up, or transferred to your account balance. They can only be used to automatically deduct pay-as-you-go bills. To top up your account, go to "Top-Up > Online Top-Up".
Can vouchers be transferred to or shared with another account?
No. Vouchers are bound to the tenant account verified at grant time and cannot be transferred to, shared with, or paid on behalf of another account. Vouchers granted to your account can only be used to deduct pay-as-you-go bills of that account.
Can expired vouchers be restored or extended?
No. Once a voucher expires, its remaining balance is automatically cleared and cannot be restored, extended, or reissued. The system deducts in the "expiring soonest first" order to help you minimize losses from expiration.
Does claiming a voucher incur any charges?
No. Vouchers credited to your account incur no fees and require no activation. Deduction is triggered only when a pay-as-you-go bill is generated from model invocations.
Can I get an invoice for the fees deducted by vouchers?
Amounts deducted by vouchers are not invoiced twice: invoices are issued based on the amount actually paid (the portion paid from your account balance), and the portion deducted by vouchers is not included in the invoiced amount. For invoicing rules, see the "Invoice Management" page.
TokenFab Domain Change Notice
Published: September 19, 2026
Dear TokenFab users,
To standardise our domain management and improve your experience, the TokenFab website will move to www.tokenfab.cn, and the previous domain www.tokenfab.com will stop serving at 18:00 on September 24, 2026 (UTC+8). Please update your configuration and integrations in time:
1. Update your API endpoint: replace api.tokenfab.com/v1 with api.tokenfab.cn/v1 in your code, SDK configuration and environment variables (e.g. the base_url of an OpenAI-compatible SDK);
2. Update your network allowlists and bookmarks: if your corporate firewall, proxy or gateway restricts outbound traffic by domain, add the new domain to the allowlist. Also update your browser bookmarks — save the new website www.tokenfab.cn and the new console www.tokenfab.cn/console;
3. Update your callbacks and integrations: if you have configured Webhook callbacks or third-party integrations, point them to the new domain and verify connectivity.
We apologise for any inconvenience this may cause, and thank you for your continued trust and support.
September 19, 2026
Model Overview
Learn about the available models and capabilities on TokenFab. All models share the same API.
Text Models
| Models ID | Context | Max output tokens | Features |
|---|---|---|---|
| glm-5.2 | 1M | 128K | Latest flagship, 1M ultra-long context, supports Web Search |
| glm-5.3 | 1M | — | Supports Web Search and tool calling |
| kimi-k3 | — | — | Flagship model; capabilities follow the API response |
| kimi-k2.7-code | 128K | 128K | Strong coding ability, excellent math reasoning |
| kimi-k2.6 | — | — | Capabilities follow the API response |
| deepseek-v4-pro | 1M | 384K | Deep reasoning and coding |
| deepseek-v4-flash | 1M | 384K | Fast response for coding and RAG |
| qwen3.7-max | 1M | 64K | Flagship model for complex reasoning and agents |
| qwen3.7-plus | 128K | 96K | Balanced quality, speed, and cost |
Video Models
| Models ID | Inputs | Supported modes | Use Case |
|---|---|---|---|
| viduq3-pro | Text + image | T2V / I2V / FLF2V | Quality-first, 540P / 720P / 1080P |
| viduq3-turbo | Text + image | T2V / I2V / FLF2V | Speed and throughput, suited to frequent drafts |
| happyhorse-1.1-t2v | Text | T2V | Text-to-video, 720P / 1080P |
| happyhorse-1.1-i2v | Text + image | I2V | Image-to-video, 720P / 1080P |
| happyhorse-1.1-r2v | Text + reference images | R2V | Reference consistency, 1-9 images |
See Video Generation Scenarios for the video endpoint request format and model parameters.
Recommended Scenarios
🏆 Best Overall — glm-5.2
1M ultra-large context, flagship performance.
💻 Coding — deepseek-v4-pro
Code generation, debugging, review.
⚡ High Concurrency — qwen3.7-max
Millisecond response, suitable for simple tasks like customer service and classification.
Token & Context Window
Understand billing units and context limits.
What is a Token
A Token is the basic unit of text processing for models:
1
English words ≈ 1 Token
1-2
Chinese characters ≈ 1-2 Tokens
usage
Actual token count returned per call
Context Window
The maximum number of tokens a model can process in one go = input + output + reasoning intermediate content.
⚠️ Warning
Exceeding the context limit may result in degraded response quality or errors.
Long Text Processing Strategies
- Use large-context models like glm-5.2.
- Process in segments and merge results.
- Use keyword search or an external retrieval service to retain relevant snippets.
- First extract key information via summarization.
Streaming Output
Real-time token-by-token output via SSE.
Enable Streaming Output
from openai import OpenAI
client = OpenAI(api_key="your-api-key", base_url="https://api.tokenfab.cn/v1")
stream = client.chat.completions.create(model="glm-5.2", messages=[{"role":"user","content":"Tell me a story"}], stream=True)
for chunk in stream:
if chunk.choices:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)SSE Data Format
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":1784950000,"model":"glm-5.2","choices":[{"index":0,"delta":{"role":"assistant","content":"Today"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":1784950000,"model":"glm-5.2","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]Thinking Mode
Let models that support this capability perform internal reasoning before output. The example uses deepseek-v4-pro.
Enable Thinking Mode
from openai import OpenAI
client = OpenAI(api_key="your-api-key", base_url="https://api.tokenfab.cn/v1")
response = client.chat.completions.create(
model="deepseek-v4-pro",
messages=[{"role": "user", "content": "What are the latest AI industry trends in 2026?"}],
extra_body={"enable_thinking":True}
)
print(response.choices[0].message.reasoning)Note
Thinking Mode is available on models that support it, such as deepseek-v4-pro, glm-5.2, and qwen3.7-max; check the model capability configuration. In Thinking Mode, temperature and other parameters do not take effect.
Function Calling
Let the model call external tools and APIs to build agent applications.
How It Works
- Send request. Include user question and tool definitions.
- Model returns tool_calls. Function name and arguments.
- Execute tool. Get results.
- Return results. Call again to get the final answer.
Full Example
tools = [{"type":"function","function":{"name":"get_weather","description":"Check weather","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}]
messages = [{"role":"user","content":"What is the weather like in Beijing?"}]
r1 = client.chat.completions.create(model="glm-5.2", messages=messages, tools=tools)
tc = r1.choices[0].message.tool_calls[0]
result = "Beijing is sunny today, 25°C"
messages.append(r1.choices[0].message)
messages.append({"role":"tool","tool_call_id":tc.id,"content":result})
r2 = client.chat.completions.create(model="glm-5.2", messages=messages)
print(r2.choices[0].message.content)Best Practices
- Tool descriptions should be clear. Affects call accuracy.
- Control the number of tools. Too many can reduce quality.
- Principle of least privilege.
Multi-turn Conversation
Maintain a messages array for multi-turn contextual conversations.
Basic Usage
messages = [{"role":"user","content":"What is the weather like in Beijing?"}]
r1 = client.chat.completions.create(model="glm-5.2", messages=messages)
messages.append({"role":"assistant","content":r1.choices[0].message.content})
messages.append({"role":"user","content":"What about Shanghai?"})
r2 = client.chat.completions.create(model="glm-5.2", messages=messages)Message Role Types
| role | Description |
|---|---|
| system | System instruction (optional) |
| user | User input |
| assistant | Model response |
| tool | Tool execution result |
JSON Mode / Structured Output
Let the model return structured data conforming to JSON Schema.
Usage Example
r = client.chat.completions.create(model="glm-5.2", messages=[{"role":"user","content":"List 3 fruits and their prices"}],
response_format={"type":"json_schema","json_schema":{"name":"fruits","schema":{"type":"object","properties":{"fruits":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string"},"price":{"type":"number"}},"required":["name","price"]}}},"required":["fruits"]}}})
print(r.choices[0].message.content)Supported JSON Schema Types
| Code | Description |
|---|---|
| object | Nested object |
| string | String |
| number / integer | Number |
| array | Array |
| boolean | Boolean |
| enum | Enum |
Async Call
Use async client for concurrent requests to improve throughput in high-concurrency scenarios.
Python Async Example
import asyncio
from openai import AsyncOpenAI
client = AsyncOpenAI(api_key="your-api-key", base_url="https://api.tokenfab.cn/v1")
async def ask(q):
r = await client.chat.completions.create(model="glm-5.2", messages=[{"role":"user","content":q}])
print(r.choices[0].message.content)
async def main():
tasks = [ask(q) for q in ["Summarize AI", "Translate Hello", "Recommend 3 books"]]
await asyncio.gather(*tasks)
asyncio.run(main())💡 Tip
Suitable for batch processing. Make sure not to exceed model rate limits.
Web Search
Enable Web Search to let the model retrieve real-time information from the internet for the latest news and data.
Enable Web Search
from openai import OpenAI
client = OpenAI(api_key="your-api-key", base_url="https://api.tokenfab.cn/v1")
response = client.chat.completions.create(
model="glm-5.2",
messages=[{"role": "user", "content": "What are the latest trends in AI in 2026?"}],
extra_body={"enable_web_search": True}
)
print(response.choices[0].message.content)Parameter Description
| Parameter | Code | Default | Description |
|---|---|---|---|
| enable_web_search | boolean | False | Whether to enable Web Search |
Use Cases
- Real-time information. Get the latest news, stock prices, weather, and other time-sensitive information.
- Fact-checking. Verify the accuracy of model responses.
- Resource supplement. Supplement knowledge beyond the training cutoff date.
Note
Web Search increases response latency. Only enable it when real-time information is needed. Search consumes additional tokens, which count toward your total usage.
Built-in Tools
Use web search, code execution and web extraction with the Responses API.
Use exact tool names
web_search
Search public web pages and cite sources.
curl -X POST https://api.tokenfab.cn/v1/responses \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.2",
"input": "What are today's top tech headlines?",
"tools": [{"type": "web_search"}]
}'code_interpreter
Run code and return the result.
curl -X POST https://api.tokenfab.cn/v1/responses \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.7-plus",
"input": "Count the days in February 2026 and compute 3 to the power of 20 exactly.",
"tools": [{"type": "code_interpreter"}]
}'Model support
web_extractor
Read a web page and extract its content.
curl -X POST https://api.tokenfab.cn/v1/responses \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.2",
"input": "Summarize the key points of this page: https://example.com",
"tools": [{"type": "web_extractor"}]
}'Difference from Chat Completions enable_web_search
Chat Completions only offers a web search switch:
curl -X POST https://api.tokenfab.cn/v1/chat/completions \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.2",
"messages": [{"role": "user", "content": "What are today's top tech headlines?"}],
"enable_web_search": true
}'How to choose
Billing
| Tool | Billing |
|---|---|
| web_search | ¥0.03/call |
| code_interpreter | No separate charge |
| web_extractor | No separate charge |
Chat Completions API
Call large language models for chat completion.
Endpoint
POST https://api.tokenfab.cn/v1/chat/completionsRequest Parameters
| Parameter | Code | Required | Description |
|---|---|---|---|
| model | string | ✓ | Models ID |
| messages | array | ✓ | Message array |
| stream | boolean | — | Streaming Output |
| temperature | number | — | Sampling temperature |
| max_tokens | integer | — | Max output tokens |
| enable_web_search | boolean | — | Web Search |
| tools | array | — | Tool definitions |
| response_format | object | — | JSON Mode |
| enable_thinking | boolean | — | Thinking Mode, available on models that support it |
Request Example
curl -X POST https://api.tokenfab.cn/v1/chat/completions \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.2",
"messages": [
{"role": "system", "content": "You are a translation assistant"},
{"role": "user", "content": "Translate the following English to Chinese: Hello World"}
],
"temperature": 0.7,
"max_tokens": 1024
}'Response Example
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"model": "glm-5.2",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello World"
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 28,
"completion_tokens": 5,
"total_tokens": 33
}
}Responses API
OpenAI Responses-compatible interface. Built-in tools (web_search, code_interpreter, web_extractor) are exclusive to this protocol; auth and billing are identical to Chat Completions.
Implementation note
Endpoint & auth
POST https://api.tokenfab.cn/v1/responsesAuth is identical to Chat Completions: send Authorization: Bearer your-api-key. No separate key is required.
Request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | ✓ | Model ID, e.g. glm-5.2 |
| input | string | array | Conditional | Some models accept instructions alone; multi-turn may use previous_response_id on supported models |
| instructions | string | — | System-level instructions, equivalent to a system message |
| stream | boolean | — | Stream output, default false |
| max_output_tokens | integer | — | Maximum output tokens; for some models, must exceed the thinking budget when reasoning is set |
| temperature | number | — | Sampling temperature, 0–2 |
| top_p | number | — | Nucleus sampling, 0–1 |
| tools | array | — | Builtin tools and function definitions, e.g. {"type":"web_search"} — see Features / Built-in Tools |
| tool_choice | string | object | — | A named tool works; none has no effect yet |
| reasoning | object | — | Reasoning effort config (model-dependent) |
| previous_response_id | string | — | Supported on some models; pass a saved previous response ID; unsaved IDs return 400 |
| store | boolean | — | Some models save responses by default (e.g. glm-5.2); send store:false explicitly if you do not want storage |
Request example
curl -X POST https://api.tokenfab.cn/v1/responses \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.2",
"input": "Describe the weather in Beijing today and cite the sources.",
"instructions": "Answer in English.",
"stream": false,
"max_output_tokens": 16384,
"temperature": 0.7,
"top_p": 0.9,
"tools": [{"type": "web_search"}],
"tool_choice": {"type": "web_search"},
"reasoning": {"effort": "low"},
"store": false
}'Full example
Streaming
curl -X POST https://api.tokenfab.cn/v1/responses \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.2",
"input": "Explain what an async task is.",
"stream": true
}'Streaming
stream: true, text arrives in chunks. Read response.output_text.delta; the stream ends with response.completed, or response.incomplete when the budget runs out.Event order: created → output_item.added → output_text.delta → output_text.done → completed. Some models also emit reasoning events; unknown events can be ignored.
Response structure
{
"id": "021793159464483fc7…",
"object": "response",
"created_at": 1793159467,
"completed_at": null,
"error": null,
"incomplete_details": null,
"instructions": null,
"max_output_tokens": null,
"max_tool_calls": null,
"model": "glm-5.2",
"output": [
{
"id": "ws_8faf6e80-b67b-4c74-9ad0-02e17b3f737f",
"type": "web_search_call",
"status": "completed",
"action": {
"type": "search",
"query": "Beijing weather today",
"sources": [
{ "type": "url", "url": "https://m.tianqi.com/tongzhou/", "title": "北京通州天气" },
{ "type": "url", "url": "http://tj.weather.com.cn/tqyw/10/4837553.shtml", "title": "今日天气" }
]
}
},
{
"id": "rs_231c7e38ea2eb8bd…",
"type": "reasoning",
"role": "assistant",
"content": [{ "type": "reasoning_text", "text": "Based on the search results…" }]
},
{
"id": "msg_006e4808292cb3ba…",
"type": "message",
"status": "completed",
"role": "assistant",
"content": [{
"type": "output_text",
"text": "Today in Beijing the weather is clear (sunny) with temperatures around 1–15°C…",
"annotations": [],
"logprobs": []
}]
}
],
"previous_response_id": null,
"prompt_cache_key": null,
"reasoning": null,
"safety_identifier": null,
"service_tier": null,
"status": "completed",
"stop_reason": "stop",
"tools": null,
"usage": {
"input_tokens": 2511,
"input_tokens_details": { "cached_read_tokens": 0, "cached_write_tokens": 0, "cached_tokens": 0 },
"output_tokens": 134,
"output_tokens_details": { "reasoning_tokens": 10, "num_search_queries": 1 },
"total_tokens": 2645
},
"extra_fields": {
"request_type": "responses",
"original_model_requested": "glm-5.2",
"latency": 3184,
"chunk_index": 0
}
}How to read the response
- Answer:
message.content[].text - Reasoning:
content[].reasoning_textorsummary[].summary_text - Tools:
web_search_callfor search,code_interpreter_callfor code execution - Fields such as
storeandstop_reasonmay be absent; request parameters are not always echoed
Differences from Chat Completions
| Aspect | Chat Completions | Responses API |
|---|---|---|
| Endpoint | /v1/chat/completions | /v1/responses |
| Input shape | messages array (role + content) | input + optional instructions |
| Output access | choices[0].message.content | output[] (SDK offers an output_text helper) |
| Usage fields | prompt_tokens / completion_tokens | input_tokens / output_tokens |
| Builtin tools | enable_web_search shortcut | Generic tools mechanism, composable |
| Server-side state | Not applicable | Supported on some models; save the previous response and pass its ID |
Guidance: existing Chat Completions integrations do not need to migrate; choose Responses API when you need builtin tools or alignment with newer protocol ecosystems (e.g. Codex-style agent tooling).
Compatibility notes
Common limitations; the actual response is authoritative.
Multi-turn support varies by model
stream_options support varies by model
document input support varies by model
store and multi-turn
Two reasoning formats
content[].reasoning_text and summary[].summary_text.tool_choice: none has no effect yet
tools if you need to disable tools.Model availability
Model availability
GET /v1/models as the source of truth.| Status | Models |
|---|---|
| Available | deepseek-v4-flash, deepseek-v4-pro, deepseek-v4.1-flash, deepseek-v4.1-flash-1017, glm-5.2, glm-5.3, glm-5.3-flash, kimi-k3, kimi-k3.1-pro, kimi-k3.1-pro-highspeed, qwen3.7-plus, qwen3.7-max, qwen3.8-flash, qwen3.8-max |
| Not available yet | the glm5.3-xy series, kimi-k2.6, kimi-k2.7-code, qwen3.7-max-2026-06-08 (calls return errors) |
| Not applicable | video models (they use the video generation APIs) |
Models List API
Query currently available models.
Endpoint
GET https://api.tokenfab.cn/v1/modelsRequest Example
curl https://api.tokenfab.cn/v1/models \
-H "Authorization: Bearer your-api-key"Response Example
{"object":"list","data":[
{"id":"aicc-doubao-seedance-2-0","object":"model","owned_by":"tokenfab"},
{"id":"deepseek-v4-flash","object":"model","owned_by":"tokenfab"},
{"id":"deepseek-v4-pro","object":"model","owned_by":"tokenfab"},
{"id":"glm-5.2","object":"model","owned_by":"tokenfab"},
{"id":"glm-5.3","object":"model","owned_by":"tokenfab"},
{"id":"happyhorse-1.1-i2v","object":"model","owned_by":"tokenfab"},
{"id":"happyhorse-1.1-r2v","object":"model","owned_by":"tokenfab"},
{"id":"happyhorse-1.1-t2v","object":"model","owned_by":"tokenfab"},
{"id":"kimi-k2.6","object":"model","owned_by":"tokenfab"},
{"id":"kimi-k2.7-code","object":"model","owned_by":"tokenfab"},
{"id":"kimi-k3","object":"model","owned_by":"tokenfab"},
{"id":"occupancy-hold","object":"model","owned_by":"tokenfab"},
{"id":"qwen3.7-max","object":"model","owned_by":"tokenfab"},
{"id":"qwen3.7-max-2026-06-08","object":"model","owned_by":"tokenfab"},
{"id":"qwen3.7-plus","object":"model","owned_by":"tokenfab"},
{"id":"viduq3-pro","object":"model","owned_by":"tokenfab"},
{"id":"viduq3-turbo","object":"model","owned_by":"tokenfab"}
]}Rate Limit & Concurrency
Rate limits are calculated at the account level.
Rate Limits (RPM / TPM)
| Models | RPM | TPM |
|---|---|---|
| glm-5.2 | 200 | 3,000,000 |
| deepseek-v4-pro | 15,000 | 1,200,000 |
| qwen3.7-plus | 30,000 | 5,000,000 |
| qwen3.7-max | 30,000 | 5,000,000 |
Note
For higher concurrency needs, contact technical support to upgrade. Exceeding limits returns HTTP 429.
Error Codes
Common error codes for API calls and troubleshooting methods.
Error Response Format
{"error":{"code":"invalid_api_key","message":"Authentication failed, please check your API Key"}}Common Error Codes
| HTTP | Code | Type | Description | Solution |
|---|---|---|---|---|
| 401 | invalid_api_key | Unauthorized | Invalid API Key | Check Authorization header |
| 403 | — | Forbidden | No Access | Check permissions |
| 404 | — | Not Found | Model Not Found | Check model name |
| 429 | — | Rate Limit | Rate Limited | Reduce frequency |
| 500 | — | Server Error | Server Error | Wait and retry |
FAQ
How to optimize costs?
Choose a model suitable for your task, reduce unnecessary context, set max_tokens appropriately, and use smaller models for testing during development.
How to handle long text?
Use large-context models like glm-5.2, process in segments and merge results, or use keyword search or an external retrieval service to retain relevant snippets.
Getting a 429 error?
Concurrency limit exceeded. Reduce call frequency, use exponential backoff retry, or request an upgrade.
Is there a billing difference between streaming and non-streaming?
No difference. Both are billed based on actual prompt_tokens + completion_tokens.
Environment variable not working?
Check: whether it's persisted in the config file, whether you restarted the IDE, and whether you used sudo.
Which programming languages are supported?
TokenFab API is compatible with the OpenAI SDK, so it supports Python, Node.js, Go, Java, and all languages with OpenAI SDKs. You can also call it directly via HTTP requests.
How to choose the right model?
For general tasks, use glm-5.2 (flagship, 1M context); for coding, use deepseek-v4-pro; for high-concurrency simple tasks, use qwen3.7-max. SeeModel Overview.
How is data security ensured?
API communication is fully encrypted via HTTPS. The platform does not store your request content for training. Some Responses API models save responses by default for multi-turn continuation; send store:false if you do not want storage. Keep your API Key secure and do not hardcode it in frontend code.
Which models support video generation?
Supports Vidu (viduq3-pro / viduq3-turbo) and HappyHorse (1.1-t2v / 1.1-i2v / 1.1-r2v) model series, covering Text-to-Video, First/Last Frame to Video and Multimodal Reference to Video. Reference-to-Video uses HappyHorse 1.1-r2v. See Video Scenarios Overview.
LangChain Integration
TokenFab API integrates with LangChain through the OpenAI-compatible interface.
Chat Model
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="glm-5.2", api_key="your-api-key", base_url="https://api.tokenfab.cn/v1")
response = llm.invoke("Introduce deep learning")💡 Tip
Frameworks compatible with the OpenAI SDK, such as LlamaIndex and Semantic Kernel, can all be directly integrated.
Video Generation Scenarios
Learn about Text-to-Video (T2V), First/Last Frame to Video (I2V / FLF2V), and Multimodal Reference to Video (R2V) to quickly understand the available video models on TokenFab, their use cases, input methods, and model selection.
Three Video Generation Modes
Text-to-Video
Input only a text prompt, and the model generates a complete video. Suitable for creative exploration without image assets.
First/Last Frame to Video
Animate an input image or use first and last frames to control the transition.
Multimodal Reference to Video
Guide subjects, style or motion with image, video or audio references, as supported by the model.
Model-Scenario Support Matrix
| Models | T2V | First/Last Frame | Reference | Positioning |
|---|---|---|---|---|
| viduq3-pro | ✅ | ✅ | — | Quality-focused |
| viduq3-turbo | ✅ | ✅ | — | Speed-focused |
| happyhorse-1.1-t2v | ✅ | — | — | Text-to-Video focused |
| happyhorse-1.1-i2v | — | ✅ | — | Image-to-Video focused |
| happyhorse-1.1-r2v | — | — | ✅ | Reference-to-Video focused |
Choose a Scenario by Need
- No image assets, only text ideas → Text-to-Video T2V
- Have an image to animate or frames that define a transition → First/Last Frame to Video I2V / FLF2V
- Need to keep characters/products/brand style consistent → Multimodal Reference to Video R2V
Text-to-Video T2V
Generate video from text prompts. The examples below use the generic POST /v1/videos API; consult the selected model’s API documentation for its endpoints and parameters.
Create a Task with the Unified Endpoint
curl -X POST https://api.tokenfab.cn/v1/videos \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "happyhorse-1.1-t2v",
"prompt": "A golden puppy running on the grass, sunny, camera following",
"seconds": "5",
"size": "1080P"
}'
# Response Example
# {"id":"vid-abc123","status":"queued","created_at":"2026-07-01T12:00:00Z"}Mode Selection Rules
| Mode | Required Fields | Must Omit | Reference Models |
|---|---|---|---|
| Text-to-Video T2V | prompt | Omit input_reference, last_frame, reference_images | happyhorse-1.1-t2v, viduq3-turbo |
| First/Last Frame to Video I2V / FLF2V | input_reference + prompt; add last_frame for paired frames | Do not combine with reference_images | happyhorse-1.1-i2v / viduq3-turbo |
| Reference-to-Video R2V | reference_images + prompt | Do not pass last_frame;1-9 images | happyhorse-1.1-r2v |
Unified Request Field Reference
| Field | Code | Purpose |
|---|---|---|
model | string | Required, use the model ID returned by /v1/models, e.g. happyhorse-1.1-t2v, viduq3-turbo |
prompt | string | Required, subject/scene/action/camera/style/lighting |
input_reference | string | I2V source image or FLF2V first frame, public URL or Base64 |
last_frame | string | FLF2V last frame |
reference_images | string[] | R2V reference image array |
seconds | string | Video duration in seconds, e.g. "3" |
size | string | Resolution, e.g. 720P, 1080P |
watermark | boolean | Watermark toggle |
negative_prompt | string | Description of content to avoid |
seed | integer | Reproducible random seed |
Async Lifecycle
1. Create
POST /v1/videos returns id
2. Poll
GET /v1/videos/{id}
3. Complete
status=completed
4. Download
status=completed, then fetch videos[0].url (or url) to download directly
Poll Task Status
# Query task status
curl https://api.tokenfab.cn/v1/videos/vid-abc123 \
-H "Authorization: Bearer your-api-key"
# Response Example (in progress, may carry progress)
# {"id":"vid-abc123","status":"in_progress","progress":45}
# Response Example (failed)
# {"id":"vid-abc123","status":"failed","error":{"message":"..."}}
# Response Example (completed)
# {"id":"vid-abc123","status":"completed","videos":[{"url":"https://cdn.tokenfab.cn/...mp4"}],"url":"https://cdn.tokenfab.cn/...mp4"}
# Download video (url from the completed response above; no API key required)
curl -o video.mp4 "https://cdn.tokenfab.cn/...mp4"Note
Video generation tasks can take a long time. Creation is not idempotent - check for existing tasks first on network timeout, do not blindly retry POST.
Failure handling
When a task fails, the HTTP status code is usually still 200. Always check the status field in the response body: status "failed" means the task failed, and the error field carries the reason (e.g. content policy violation, generation timeout). Possible values: queued / in_progress / completed / failed. Additionally, tasks cancelled or timed out upstream may return cancelled / expired, both of which are terminal states. Any status other than queued or in_progress should be treated as a terminal state to stop polling.
First/Last Frame to Video I2V / FLF2V
Provide an image to animate it, or first and last frames to control a transition. Supported single/paired-frame inputs depend on the selected model.
Create a Task with the Unified Endpoint
Single-frame example
curl -X POST https://api.tokenfab.cn/v1/videos \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "happyhorse-1.1-i2v",
"prompt": "Camera slowly pushes in, a girl slightly turns her head and smiles",
"input_reference": "https://example.com/photo.jpg",
"seconds": "5",
"size": "1080P"
}'Paired-frame example
curl -X POST https://api.tokenfab.cn/v1/videos \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "viduq3-turbo",
"prompt": "City skyline transitioning from day to night, lights gradually turning on",
"input_reference": "https://example.com/first_frame.jpg",
"last_frame": "https://example.com/last_frame.jpg",
"seconds": "5",
"size": "1080P"
}'Integration Checklist
- Request structure: Use
model+input_reference+promptfor the single-frame example; addlast_framefor paired frames. First/last-frame requirements depend on the model. Do not combine frames withreference_images. - Asset requirements: Use clear images with a distinct subject. Keep the subject, style and composition continuous across paired frames; describe the motion path when the frames differ significantly.
- Image format: The examples use public URLs. Complete Base64 Data URLs may be used where supported by the model API. Do not pass local paths or private network URLs.
- Model selection: The single-image example uses HappyHorse I2V and the paired-frame example uses ViduQ3-Turbo. Choose a compatible model for the desired quality or speed.
Production Integration Tips
Polling Backoff
Start with 2-5 seconds, gradually back off, set a business timeout.
Idempotency & Tracking
Save the request ID and returned video_id; check logs first on timeout.
Security Boundaries
Do not expose API tokens on the frontend; control the expiration of public URLs.
Multimodal Reference to Video R2V
Use image, video or audio references as subject, style, composition or motion constraints. Supported media and limits depend on the selected model; the example below demonstrates image references.
Create a Task with the Unified Endpoint
curl -X POST https://api.tokenfab.cn/v1/videos \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "happyhorse-1.1-r2v",
"prompt": "The person in [Image 1] walks down the street, keeping the outfit style consistent",
"reference_images": [
"https://example.com/ref1.jpg",
"https://example.com/ref2.jpg"
],
"seconds": "5",
"size": "1080P"
}'Integration Checklist
- Request structure: Pass
model+reference_images+prompt, Omitlast_frame. - Number of images: HappyHorse supports 1-9 reference images; Vidu does not support Multimodal Reference to Video.
- Prompt tips: Use [Image 1], [Image 2] to reference the order of reference images, specifying which elements must remain consistent and which can vary.
- Media types: Use video or audio references only when supported by the selected model, following its API schema. Do not mix reference media with first/last-frame inputs.
Key Differences
First/Last Frame to Video focuses on animating an image or controlling the transition between frames; R2V focuses on referencing the features of the input image, to generate new frames that remain consistent.