tcpapi API
An exchange and clearinghouse for AI inference. Each request is matched to the cheapest backend that meets your price and speed limits. If that backend stalls partway through an answer, the clearinghouse buys a replacement and the same stream carries on from the next token.
Get an API key at https://tcpapi.com. The model tinylm-a is a
free sandbox that answers with placeholder words.
Use it
Point any OpenAI- or Anthropic-compatible client at https://api.tcpapi.com. Nothing else is
required: each model has a default price limit.
curl -N https://api.tcpapi.com/v1/chat/completions \
-H "Authorization: Bearer $TCPAPI_KEY" \
-d '{"model":"tinylm-a","max_tokens":32,"stream":true,
"messages":[{"role":"user","content":"hello"}]}'
With the OpenAI Python SDK:
from openai import OpenAI
client = OpenAI(base_url="https://api.tcpapi.com/v1", api_key=TCPAPI_KEY)
stream = client.chat.completions.create(
model="tinylm-a", max_tokens=32, stream=True,
messages=[{"role": "user", "content": "hello"}])
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")
Request headers
| Header | Meaning |
|---|---|
Authorization: Bearer <key> | Your API key. Anthropic-style clients can send x-api-key instead. |
X-Limit-Price | Optional. The most you'll pay, in US dollars per million output tokens (default: the model's list price). |
X-Max-TTFT-Us | Optional. The longest acceptable wait for the first token, in microseconds. |
X-Min-TPS | Optional. The slowest acceptable output speed, in tokens per second. |
Endpoints
| Path | What it does |
|---|---|
POST /v1/chat/completions | OpenAI chat format, streaming or not. |
POST /v1/messages | Anthropic Messages format. |
GET /v1/models | The models you can buy. |
GET /health | Returns {"status":"ok"} when the service is up. |
What happens to a request
- Your key's credit is checked, and the most the request could cost is set aside.
- The request is matched to the cheapest seller that meets your price and speed limits.
- Tokens stream back to you as they're generated, and each one is metered.
- If the seller stalls, the clearinghouse buys the rest of the answer from a backup. The backup resumes where the first seller stopped, and you still pay only the original price.
- You're charged for the tokens you received, plus your input tokens at the model's input weight. Every reply carries its usage, and the stream ends with a receipt: a BLAKE3 hash of every token with its arrival time.
The failover notice and the receipt arrive as SSE comment lines starting with :, which
standard clients ignore. Non-streaming replies carry the same details in an aethelgard field.
Errors
| Status | Meaning |
|---|---|
| 400 | Invalid request, refused by the model (e.g. longer than its context), or a feature not
supported yet (tool calling, images, n > 1, logprobs). |
| 401 | Missing or unknown API key. |
| 402 | Not enough credit for the most this request could cost. |
| 429 | Too many requests open at once on your account (the limit is 16). |
| 503 | No seller meets your price and speed limits right now. |