Skip to main content
The REST API lets you manage your TokenChange account from code: browse the catalog, manage inference keys, read usage and billing, and run your provider endpoints. To call models, use the inference API instead.

Base URL

All routes are under /v1 and use JSON. The OpenAPI specification is available at https://api.tokenchange.io/v1/openapi.json.

Authentication

Authenticate with an API token as a Bearer token:
API tokens start with tcg_. They can’t make inference requests, and inference keys can’t call the REST API.

Create an API token

1

Open API tokens

In the dashboard, open Account > API tokens.
2

Name the token and choose scopes

Use a name that says where the token runs, such as deploy pipeline. Pick only the scopes it needs, and optionally an expiry.
3

Copy the token

The token is shown once. Store it in a secret manager.
From the same page you can Edit a token’s name, scopes and expiry, Rotate it to get a new secret and invalidate the old one, or Revoke it. You can have up to 25 active tokens. API tokens are managed only in the dashboard, not through the REST API.

Scopes

Each token carries one or more scopes. A request to a route outside the token’s scopes fails with 403 insufficient_scope. Write scopes don’t include the matching read scope, so add both if you need both. Each route’s required scope is listed on its reference page.

Units

Credit amounts are integers in microcredits, in fields ending in _micro. One credit is 1,000,000 microcredits, and one credit is worth $0.01. Prices are decimal strings in USD per million tokens.

Pagination

List routes return a page of results and a cursor:
Pass next_cursor as the cursor query parameter to get the next page. limit sets the page size, from 1 to 100 (default 20). When there are no more results, next_cursor is null.

Rate limits

Requests are rate-limited per token and per account in one-minute windows. Every authenticated response includes the limit that’s closest to running out: Over the limit, you get 429 rate_limited with a Retry-After header in seconds.

Idempotency

POST routes accept an optional Idempotency-Key header of 1 to 255 printable ASCII characters. Send a unique value, such as a UUID, to retry a request safely:
  • Retrying with the same key and the same request returns the original response with Idempotent-Replayed: true, for 24 hours.
  • Reusing a key with a different request fails with 422 idempotency_key_reused.
  • Retrying while the first request is still running fails with 409 idempotency_in_progress.
  • Responses that contain a secret, such as a new inference key, are never stored. Replaying one fails with 409 idempotency_secret_unavailable, and resource_id holds the ID of the key that was created.
Failed requests don’t keep their key, so you can retry them with the same key.

Request IDs

Every response has an X-Request-Id header. Send your own X-Request-Id (up to 128 letters, digits, -, _ or .) to use it instead. Include it when you contact support.

Errors

Errors share one format: