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. 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

JSON response
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

base URL ends in /v1
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

base URL without /v1
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

base URL ends in /v1
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

writes hello.wav
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.wav

OpenAI SDK · Python

writes hello.wav
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

writes hello.wav
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

uploads hello.wav
curl --fail-with-body https://api.tokenflow.dev/v1/audio/transcriptions \
  -H "Authorization: Bearer $TOKENFLOW_API_KEY" \
  -F model=sensevoice-small \
  -F file=@hello.wav

OpenAI SDK · Python

uploads hello.wav
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

uploads hello.wav
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

Every model, with its own page for limits, prices and examples.
ModelTypeGood for
qwen3.8-27bLanguage & chatGeneral chat, coding agents and tool use. Our default model.
qwen3.8-27b-directLanguage & chatQwen3.8 27B with an adapter that declines fewer requests.
qwen3.8-27b-cuteLanguage & chatThe direct model with a casual, short, emoji-friendly chat persona.
gemma4-12bLanguage & chatSmaller and faster. Good for short chat, extraction and image questions.
gemma4-12b-directLanguage & chatGemma 4 12B with an adapter that declines fewer requests.
sensevoice-smallSpeech to textTranscribe short WAV recordings to text.
tokenflow-tts-1Text to speechGenerate speech from text using preset or described voices.

Next steps

Can't connect?

The usual first errors. Every code is on the API errors page.
StatusCodeWhat to do
400unsupported_audioTranscription takes PCM WAV only. Convert MP3 or other formats first.
400audio_too_longThe recording is longer than 30 seconds. Split it into shorter WAV files.
401unauthorizedThe key is missing or wrong. Send it as Authorization: Bearer (OpenAI) or x-api-key (Anthropic).
404model_not_foundCheck 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.
429quota_exceededYour organization's monthly token allowance is used up. Retrying will not help until it resets or is raised.
429speech_quota_exceededThe 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.
503no_serving_nodeNo node can serve the model right now. Retry after the Retry-After header.