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

HeaderMeaning
Authorization: Bearer <key>Your API key. Anthropic-style clients can send x-api-key instead.
X-Limit-PriceOptional. The most you'll pay, in US dollars per million output tokens (default: the model's list price).
X-Max-TTFT-UsOptional. The longest acceptable wait for the first token, in microseconds.
X-Min-TPSOptional. The slowest acceptable output speed, in tokens per second.

Endpoints

PathWhat it does
POST /v1/chat/completionsOpenAI chat format, streaming or not.
POST /v1/messagesAnthropic Messages format.
GET /v1/modelsThe models you can buy.
GET /healthReturns {"status":"ok"} when the service is up.

What happens to a request

  1. Your key's credit is checked, and the most the request could cost is set aside.
  2. The request is matched to the cheapest seller that meets your price and speed limits.
  3. Tokens stream back to you as they're generated, and each one is metered.
  4. 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.
  5. 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

StatusMeaning
400Invalid request, refused by the model (e.g. longer than its context), or a feature not supported yet (tool calling, images, n > 1, logprobs).
401Missing or unknown API key.
402Not enough credit for the most this request could cost.
429Too many requests open at once on your account (the limit is 16).
503No seller meets your price and speed limits right now.