# TokenCamel API Docs One API key for Claude, GPT, DeepSeek, Gemini, Qwen and other major models. This page is also available as plain text: [简体中文](https://tokencamel.com/docs.md) · [繁體中文](https://tokencamel.com/docs.zh-TW.md) · [English](https://tokencamel.com/docs.en.md). ## Quickstart 1. Sign up at [tokencamel.com/sign-up](https://tokencamel.com/sign-up). 2. Sign in to the console and create an API key on the API Keys (令牌) page. Keys start with `sk-`. Use separate keys per project if you like. 3. Base URL: | Used by | Base URL | |---|---| | OpenAI SDKs and OpenAI-compatible clients | `https://api.tokencamel.com/v1` | | Anthropic SDKs, Claude Code | `https://api.tokencamel.com` (no `/v1`) | 4. Authentication: `Authorization: Bearer sk-xxxx` or `x-api-key: sk-xxxx`. Both work. Your first request: ```bash curl https://api.tokencamel.com/v1/chat/completions \ -H "Authorization: Bearer sk-xxxx" \ -H "Content-Type: application/json" \ -d '{"model":"gpt-5.5","messages":[{"role":"user","content":"Hello"}]}' ``` Model names are listed on the [Models & Pricing](https://tokencamel.com/pricing) page and by `GET /v1/models`. The model names on this page are examples. ## Choose the right API format **This is the most important section.** The same model called through different API formats gets different prompt caching, and the cost difference is large. Cached input is billed at a fraction of the input price (about a tenth for Claude); uncached input is billed at the full price. | Model | API format | Prompt cache | |---|---|---| | Claude | Anthropic format `POST /v1/messages` (streaming and non-streaming) | Hit | | Claude | OpenAI format `POST /v1/chat/completions` | **Never** | | GPT | OpenAI format `POST /v1/chat/completions` (streaming) | Hit (automatic) | | GPT | `POST /v1/responses` | Hit (automatic) | | DeepSeek, Gemini | OpenAI format or Anthropic format | Hit (automatic) | ### Use the Anthropic format for Claude When Claude is called through the OpenAI format, the gateway drops the cache markers while converting the request, so every turn is billed at the full input price. For long chats, agents and large system prompts this costs several times more. **Always call Claude through the Anthropic format `/v1/messages`**, and add `cache_control` the way Anthropic documents it. ```bash curl https://api.tokencamel.com/v1/messages \ -H "x-api-key: sk-xxxx" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-sonnet-5-5", "max_tokens": 1024, "system": [{"type": "text", "text": "", "cache_control": {"type": "ephemeral"}}], "messages": [{"role": "user", "content": "Hello"}] }' ``` ### Other models - GPT, DeepSeek, Gemini, Qwen, GLM, Kimi and others: use the OpenAI format `/v1/chat/completions`. Caching is automatic; no extra parameters are needed. - Codex and other tools that use the Responses API: use `/v1/responses`. ## Client setup ### Claude Code ```bash export ANTHROPIC_BASE_URL=https://api.tokencamel.com export ANTHROPIC_AUTH_TOKEN=sk-xxxx export ANTHROPIC_SMALL_FAST_MODEL=claude-haiku-5-5 claude ``` Do not add `/v1` to `ANTHROPIC_BASE_URL`. Set the small/fast model to a haiku model such as `claude-haiku-5-5` so Claude Code's background calls are cheaper and faster. ### Claude Desktop with CC Switch Add a provider in CC Switch: - Mode: direct (直连). - Request URL: `https://api.tokencamel.com`, **with no trailing slash and no `/v1`**. - API key: `sk-xxxx`. - Model mapping: fill in all four model slots. If only the Haiku slot is set, the other slots keep the client's built-in older defaults, and the model picker shows only the previous-generation flagships. | CC Switch slot | Value | |---|---| | Main model | `claude-sonnet-5-5` | | Opus | `claude-opus-5-5` | | Sonnet | `claude-sonnet-5-5` | | Haiku | `claude-haiku-5-5` | You can also paste this into CC Switch's config JSON: ```json { "env": { "ANTHROPIC_BASE_URL": "https://api.tokencamel.com", "ANTHROPIC_AUTH_TOKEN": "sk-xxxx", "ANTHROPIC_MODEL": "claude-sonnet-5-5", "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5", "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5-5", "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-5-5" } } ``` Sonnet as the main model covers everyday coding at a much lower cost than Opus; switch to Opus with `/model` for hard problems. To use `claude-fable-5-1` for a while, type `/model claude-fable-5-1` in Claude Code. Don't make it the default: it has the highest price. ### Codex In `~/.codex/config.toml` (Windows: `%USERPROFILE%\.codex\config.toml`), add TokenCamel as a provider and make it the default. The default model is `gpt-6.1-sol`. Leave your other settings as they are: ```toml # ~/.codex/config.toml model_provider = "tokencamel" model = "gpt-6.1-sol" [model_providers.tokencamel] name = "TokenCamel" base_url = "https://api.tokencamel.com/v1" wire_api = "responses" requires_openai_auth = true ``` Then save the key with Codex's own login command (if you signed in to Codex with a ChatGPT account, this replaces that sign-in; back up `~/.codex/auth.json` first if you want to switch back): ```bash printf '%s' 'sk-xxxx' | codex login --with-api-key ``` Restart Codex to apply. The CC Switch import buttons and the "Copy for your AI" prompt in the home page's One-click setup section do all of this for you. ### Cursor and Cherry Studio In OpenAI-compatible mode, set the URL to `https://api.tokencamel.com/v1` and the key to `sk-xxxx`; it works. Note: Claude does **not** get prompt caching in OpenAI-compatible mode (see "Choose the right API format"). If the client supports Anthropic-format providers, use that for Claude. ### OpenAI SDK (Python) ```python from openai import OpenAI client = OpenAI(base_url="https://api.tokencamel.com/v1", api_key="sk-xxxx") resp = client.chat.completions.create( model="gpt-5.5", messages=[{"role": "user", "content": "Hello"}], ) print(resp.choices[0].message.content) ``` ### OpenAI SDK (Node) ```javascript import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://api.tokencamel.com/v1", apiKey: "sk-xxxx" }); const resp = await client.chat.completions.create({ model: "gpt-5.5", messages: [{ role: "user", content: "Hello" }], }); console.log(resp.choices[0].message.content); ``` ### Anthropic SDK (Python) ```python import anthropic client = anthropic.Anthropic(base_url="https://api.tokencamel.com", api_key="sk-xxxx") msg = client.messages.create( model="claude-sonnet-5-5", max_tokens=1024, messages=[{"role": "user", "content": "Hello"}], ) print(msg.content[0].text) ``` ### Anthropic SDK (Node) ```javascript import Anthropic from "@anthropic-ai/sdk"; const client = new Anthropic({ baseURL: "https://api.tokencamel.com", apiKey: "sk-xxxx" }); const msg = await client.messages.create({ model: "claude-sonnet-5-5", max_tokens: 1024, messages: [{ role: "user", content: "Hello" }], }); console.log(msg.content[0].text); ``` ## Models Models are added and removed over time. The live list is on the [Models & Pricing](https://tokencamel.com/pricing) page and from `GET /v1/models`: ```bash curl https://api.tokencamel.com/v1/models -H "Authorization: Bearer sk-xxxx" ``` Model families: Claude, GPT, Gemini, DeepSeek, Qwen, GLM, Kimi; image models such as gpt-image, Seedream, Gemini image and Qwen image; video models Wan and HappyHorse. ### Standard and official routes Some Claude and GPT models are served on two routes, told apart by the model name. The same API key works for both; there is nothing extra to apply for. | Route | Model name | Notes | |---|---|---| | Standard route | The plain name, for example `claude-opus-5-5` | Lower price | | Official route | The plain name plus `-official`, for example `claude-opus-5-5-official` | Served through the official API, higher price | - Models with an official route: `claude-opus-5-5`, `claude-opus-5`, `claude-opus-4-8`, `claude-opus-4-7`, `claude-opus-4-6`, `claude-sonnet-5-5`, `claude-sonnet-5`, `claude-sonnet-4-6`, `claude-fable-5-1`, `claude-fable-5`, `gpt-5.5`, `gpt-5.6-sol`, `gpt-5.6-terra`, `gpt-5.6-luna`, `gpt-6-astra`, `gpt-image-2`. - Every other model has a single route; use its plain name. - The two names are priced separately; see the [Models & Pricing](https://tokencamel.com/pricing) page. - The routes never fail over to each other. If the standard route is temporarily unavailable the request returns an error; switch to the `-official` name yourself when you need to. - API formats and caching rules are the same as for the plain name; keep using the Anthropic format for Claude. To run Claude Code on the official route, set the model names to the `-official` ones. Haiku stays as it is: ```bash export ANTHROPIC_MODEL=claude-sonnet-5-5-official export ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-5-5-official export ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-5-5-official ``` ## Images ### Text to image ```bash curl https://api.tokencamel.com/v1/images/generations \ -H "Authorization: Bearer sk-xxxx" \ -H "Content-Type: application/json" \ -d '{"model":"qwen-image-3.0","prompt":"a small camel walking on sand dunes, simple flat illustration","n":1,"size":"1024x1024"}' ``` Call `qwen-image-3.0` and `qwen-image-3.0-pro` with the text-to-image endpoint above; use `size` for 2K images. ### Image to image: gpt-image `gpt-image-2`, `gpt-image-2.5-flare` and `gpt-image-2.5-sunburst` use `POST /v1/images/edits` with a multipart upload: ```bash curl https://api.tokencamel.com/v1/images/edits \ -H "Authorization: Bearer sk-xxxx" \ -F model=gpt-image-2 \ -F prompt="Turn this logo into a golden embossed metal badge" \ -F image=@logo.png \ -F size=1024x1024 \ -F quality=low \ -F n=1 ``` - Parameters: `model`, `prompt`, `image` (the file), and optionally `size`, `quality` (`low` / `medium` / `high`), `n`. - Output formats are png and jpeg only; asking for webp returns 400. - A transparent background works with png only. - `high` quality uses about 7 times the tokens of `low` and can take 1–2 minutes; set a long timeout. ### Image to image: Seedream and Qwen Image `seedream-4-5-251128`, `dola-seedream-5-0-pro-260628`, `qwen-image-3.0` and `qwen-image-3.0-pro` use the generation endpoint `/v1/images/generations` with an https URL of the reference image in `image`: ```bash curl https://api.tokencamel.com/v1/images/generations \ -H "Authorization: Bearer sk-xxxx" \ -H "Content-Type: application/json" \ -d '{"model":"seedream-4-5-251128","prompt":"Turn this logo into a golden embossed metal badge","image":"https://example.com/logo.png","size":"2048x2048","n":1}' ``` `seedream-4-5-251128` needs at least 3,686,400 pixels (for example `2048x2048`); smaller sizes return 400. Qwen Image takes 1–3 reference images (pass `image` as an array of URLs or `data:image/...;base64,` strings), or upload 1–3 image files through `/v1/images/edits` the same way as gpt-image; each reference image is billed. `qwen-image-3.0-pro` output above about 2.25 million pixels (for example `2048x2048`) is billed as 2K, otherwise 1K. For text to image, leave out `image`. ### Image to image: Gemini image models `gemini-nano-banana-2.1`, `gemini-3.1-flash-image` and `gemini-3-pro-image` use the chat endpoint `/v1/chat/completions`: send an `image_url` part (a data URI or an image URL) plus a text instruction. The generated image comes back in the chat reply. ```bash curl https://api.tokencamel.com/v1/chat/completions \ -H "Authorization: Bearer sk-xxxx" \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-nano-banana-2.1", "messages": [{"role": "user", "content": [ {"type": "text", "text": "Turn this logo into a golden embossed metal badge"}, {"type": "image_url", "image_url": {"url": "https://example.com/logo.png"}} ]}] }' ``` ## Video Video generation is asynchronous: submit, poll the status, download. ```bash curl -X POST https://api.tokencamel.com/v1/videos \ -H "Authorization: Bearer sk-xxxx" \ -H "Content-Type: application/json" \ -d '{"model":"wan3.0-video","prompt":"a camel walking across sand dunes at sunset","seconds":5,"resolution":"720P","ratio":"16:9"}' # {"id":"task_...","status":"queued",...} curl https://api.tokencamel.com/v1/videos/task_... -H "Authorization: Bearer sk-xxxx" # status: queued -> in_progress -> completed / failed ``` Download the video **within 24 hours** of completion; after that the link expires and the task ID can no longer be looked up. Failed tasks are not charged. ### Wan `wan3.0-video`, `wan3.0-video-prime`: - `seconds`: 2–30. - `resolution`: `480P` / `720P` / `1080P`, default `1080P`. - `ratio`: `16:9`, `9:16`, `1:1`, `4:3`, `3:4`, `adaptive`. - `image`: first-frame image URL; when present the request is image to video. ### HappyHorse ```bash curl -X POST https://api.tokencamel.com/v1/videos -H "Authorization: Bearer sk-xxxx" -H "Content-Type: application/json" \ -d '{"model":"happyhorse-1.1-t2v","prompt":"a camel walking across sand dunes at sunset","seconds":5,"resolution":"720P","ratio":"16:9"}' curl -X POST https://api.tokencamel.com/v1/videos -H "Authorization: Bearer sk-xxxx" -H "Content-Type: application/json" \ -d '{"model":"happyhorse-1.1-i2v","prompt":"the person slowly smiles","image":"https://example.com/first.png","seconds":5,"resolution":"720P"}' curl -X POST https://api.tokencamel.com/v1/videos -H "Authorization: Bearer sk-xxxx" -H "Content-Type: application/json" \ -d '{"model":"happyhorse-1.1-r2v","prompt":"[Image 1] walks in the snow","images":["https://example.com/ref1.png"],"seconds":5,"resolution":"720P","ratio":"16:9"}' ``` - `happyhorse-1.1-t2v` is text to video. `happyhorse-1.1-i2v` is image to video: `image` is the first frame (a public URL or `data:image/...;base64,...`); `ratio` is not supported and the aspect ratio follows the first frame. `happyhorse-1.1-r2v` is reference to video: put 1–9 reference images in `images` and refer to them in `prompt` as `[Image 1]`, `[Image 2]` in order. - `seconds`: an integer from 3 to 15, default 5. - `resolution`: `480P` / `720P` / `1080P`, default `1080P`; or use `size`, for example `1280x720`. - `ratio` (t2v, r2v): `16:9`, `9:16`, `1:1`, `4:3`, `3:4`, `4:5`, `5:4`, `9:21`, `21:9`. - Optional: `watermark`, `seed` (0–2147483647). - Out-of-range parameters, i2v without a first frame, r2v without reference images or without `prompt`, and t2v with images return 400 right away and are not charged. - Image URLs must be downloadable from the public internet; if the download fails, the task fails (not charged). - Input images (the i2v first frame, r2v reference images): JPEG / JPG / PNG / WEBP; width and height both at least 300 px; aspect ratio between 1:2.5 and 2.5:1; up to 20 MB; a public http(s) URL or `data:{mime};base64,...` where the MIME type matches the file. - `prompt`: up to 2,500 Chinese characters or 5,000 other characters; longer prompts are truncated. - `watermark` defaults to true and adds a "Happy Horse" mark in the bottom-right corner; send `"watermark": false` if you don't want it. - Output is MP4 (H.264, 24 fps). Generation usually takes 1–5 minutes; poll about every 15 seconds. ## Billing Prices are on the [Models & Pricing](https://tokencamel.com/pricing) page; this document lists none. The rules: - Chat models are billed by tokens, in four kinds: input, output, cache read and cache write. Cache reads are billed at a fraction of the input price. - Images are billed per image, or by image tokens, depending on the model. - Video is billed per second, with a rate that depends on resolution. Failed tasks are not charged. - Pre-deduction: when your balance is low, the gateway reserves the worst-case cost of a request before running it and settles the actual cost afterwards. Keeping a balance above about 10 CNY usually avoids pre-deduction failures. - Refunds: see the [refund policy](https://tokencamel.com/brand/refund.html). ## Errors | Status | Cause | What to do | |---|---|---| | 401 | Wrong or deleted API key | Check that the key is complete and starts with `sk-` | | 403 | "预扣费额度失败" / insufficient quota for pre-deduction: the balance cannot cover this request's reservation | Top up; keep the balance above about 10 CNY | | 404 | Unknown or misspelled model name | Check the name with `GET /v1/models` | | 429 | Too many requests, rate limited | Lower concurrency and retry later | | 400 | Invalid parameters, such as webp or a non-png transparent background on gpt-image, a seedream-4.5 size that is too small, or out-of-range video parameters | Follow the limits in the "Images" and "Video" sections | ## Contact Integration questions and enterprise purchasing: [hello@tokencamel.com](mailto:hello@tokencamel.com).