Docs
Quickstart
One key and one base URL for chat, speech and transcription. Set them up once, then send a first request of each kind.
1. Get an API key
tokenflow is available by invitation: request access. Once invited, sign in to the console.You are signed in to the console. An owner of your organization creates keys on its Usage & keys page; if you are a member, ask an owner for one. A key is shown once, when it is created; store it somewhere safe. The same key works for every model.
2. Set the key and the base URL
export TOKENFLOW_API_KEY=… # the key from the console
- OpenAI SDKs
https://api.tokenflow.dev/v1- Anthropic SDKs
https://api.tokenflow.dev(the SDK adds/v1)
Chat works with either SDK. Speech and transcription follow OpenAI's audio API, so use an OpenAI SDK or curl for them.
3. Send a first request
Pick the one you need. Chat and speech run on their own; transcription needs a WAV file, which the speech example writes.
Chat
Send a message to qwen3.8-27b. The reply is in choices[0].message.content (OpenAI) or content[0].text (Anthropic).
curl
curl https://api.tokenflow.dev/v1/chat/completions \
-H "Authorization: Bearer $TOKENFLOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "qwen3.8-27b", "messages": [{"role": "user", "content": "Hello"}]}'OpenAI SDK · Python
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.tokenflow.dev/v1", api_key=os.environ["TOKENFLOW_API_KEY"])
reply = client.chat.completions.create(model="qwen3.8-27b", messages=[{"role": "user", "content": "Hello"}])
print(reply.choices[0].message.content)Anthropic SDK · Python
import os
from anthropic import Anthropic
client = Anthropic(base_url="https://api.tokenflow.dev", api_key=os.environ["TOKENFLOW_API_KEY"])
reply = client.messages.create(model="qwen3.8-27b", max_tokens=1024, messages=[{"role": "user", "content": "Hello"}])
print(reply.content[0].text)OpenAI SDK · TypeScript
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.tokenflow.dev/v1", apiKey: process.env.TOKENFLOW_API_KEY });
const reply = await client.chat.completions.create({ model: "qwen3.8-27b", messages: [{ role: "user", content: "Hello" }] });
console.log(reply.choices[0].message.content);Speech
Have tokenflow-tts-1 say “你好,欢迎使用语音服务。” (“Hello, welcome to the speech service.”) in the zh-female-calm voice and save it as hello.wav. Leave out response_format to get MP3. If curl reports an error, hello.wav holds the error JSON instead of audio: cat hello.wav to see why.
curl
curl --fail-with-body https://api.tokenflow.dev/v1/audio/speech \
-H "Authorization: Bearer $TOKENFLOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "tokenflow-tts-1", "voice": "zh-female-calm", "input": "你好,欢迎使用语音服务。", "response_format": "wav"}' \
--output hello.wavOpenAI SDK · Python
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.tokenflow.dev/v1", api_key=os.environ["TOKENFLOW_API_KEY"])
with client.audio.speech.with_streaming_response.create(
model="tokenflow-tts-1", voice="zh-female-calm", input="你好,欢迎使用语音服务。", response_format="wav"
) as audio:
audio.stream_to_file("hello.wav")OpenAI SDK · TypeScript
import fs from "node:fs";
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.tokenflow.dev/v1", apiKey: process.env.TOKENFLOW_API_KEY });
const audio = await client.audio.speech.create({ model: "tokenflow-tts-1", voice: "zh-female-calm", input: "你好,欢迎使用语音服务。", response_format: "wav" });
fs.writeFileSync("hello.wav", Buffer.from(await audio.arrayBuffer()));Choose another voice from the voice list, or describe one with instructions instead of voice. For long text (up to 4,000 characters a request), stream the audio. The audio is AI-generated: tell your listeners, and keep the origin label each response carries. The speech guide covers both.
Transcription
Turn hello.wav back into text with sensevoice-small, or upload a WAV recording of your own of up to 30 seconds.
curl
curl --fail-with-body https://api.tokenflow.dev/v1/audio/transcriptions \
-H "Authorization: Bearer $TOKENFLOW_API_KEY" \
-F model=sensevoice-small \
-F file=@hello.wavOpenAI SDK · Python
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.tokenflow.dev/v1", api_key=os.environ["TOKENFLOW_API_KEY"])
with open("hello.wav", "rb") as f:
result = client.audio.transcriptions.create(model="sensevoice-small", file=f)
print(result.text)OpenAI SDK · TypeScript
import fs from "node:fs";
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.tokenflow.dev/v1", apiKey: process.env.TOKENFLOW_API_KEY });
const result = await client.audio.transcriptions.create({ model: "sensevoice-small", file: fs.createReadStream("hello.wav") });
console.log(result.text);curl prints something like:
{"text":"你好,欢迎使用语音服务。","usage":{"type":"duration","seconds":10}}
usage.seconds is the billed duration: a request is billed for at least 10 seconds of audio. Ask for response_format=verbose_json to get the language and duration as well.
Choose a model
| Model | Type | Good for |
|---|---|---|
qwen3.8-27b | Language & chat | General chat, coding agents and tool use. Our default model. |
qwen3.8-27b-direct | Language & chat | Qwen3.8 27B with an adapter that declines fewer requests. |
qwen3.8-27b-cute | Language & chat | The direct model with a casual, short, emoji-friendly chat persona. |
gemma4-12b | Language & chat | Smaller and faster. Good for short chat, extraction and image questions. |
gemma4-12b-direct | Language & chat | Gemma 4 12B with an adapter that declines fewer requests. |
sensevoice-small | Speech to text | Transcribe short WAV recordings to text. |
tokenflow-tts-1 | Text to speech | Generate speech from text using preset or described voices. |
Next steps
- Coding agentsPoint Claude Code or Codex at tokenflow.
- Speech guideEvery voice, other audio formats, streaming long text, quotas and disclosure.
- PlaygroundChat, speak and transcribe in the console without writing code.
- PricingReference prices and how usage and quotas are counted.
- API errorsEvery error code and what to do about it.
- Agent guideThe same instructions written for coding agents.
Can't connect?
| Status | Code | What to do |
|---|---|---|
| 400 | unsupported_audio | Transcription takes PCM WAV only. Convert MP3 or other formats first. |
| 400 | audio_too_long | The recording is longer than 30 seconds. Split it into shorter WAV files. |
| 401 | unauthorized | The key is missing or wrong. Send it as Authorization: Bearer (OpenAI) or x-api-key (Anthropic). |
| 404 | model_not_found | Check both the model ID and the endpoint: chat models answer on the chat paths (/v1/chat/completions, /v1/messages and the like), speech and transcription on their own. GET /v1/models with your key lists the IDs it can use. |
| 429 | quota_exceeded | Your organization's monthly token allowance is used up. Retrying will not help until it resets or is raised. |
| 429 | speech_quota_exceeded | The monthly speech or transcription allowance is used up, or speech is not enabled for your organization. Do not retry; write to support to enable speech or raise the quota. |
| 503 | no_serving_node | No node can serve the model right now. Retry after the Retry-After header. |