TokenHub provides a unified OpenAI-compatible endpoint that routes your requests across LLM providers automatically. This guide walks you through sending your first chat completion request, reading the response, and handling common errors.Documentation Index
Fetch the complete documentation index at: https://docs.inferoute.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- A TokenHub API key (find it in the dashboard)
- One of: Python with the
openailibrary, Node.js with theopenaipackage, orcurl
Send your first request
Install the client library
Install the OpenAI SDK for your language. TokenHub is fully compatible with it — you only need to set the
base_url.Send a chat completion
Make a request using any model available through TokenHub. The
model field accepts provider-prefixed names like openai/gpt-4o.Response fields explained
| Field | Description |
|---|---|
id | A unique identifier for this completion request, useful for support and debugging. |
model | The exact provider model that served the request. This may differ from what you requested if TokenHub applied routing or fallback. |
choices | An array of generated responses. Most requests return one choice unless you set n > 1. |
choices[0].message.content | The text of the assistant’s reply. |
choices[0].finish_reason | Why the model stopped generating: stop (natural end), length (hit max_tokens), or content_filter. |
usage | Token counts for the request. You are billed based on these figures against the provider that served the request. |
Troubleshooting
401 Unauthorized
Your API key is missing, malformed, or revoked.- Confirm the key starts with
th-and has no trailing whitespace. - Check the API Keys page to ensure the key is active.
- Verify you are setting the
Authorization: Bearer <key>header, notX-API-Key.
429 Too Many Requests
You have exceeded your rate limit or monthly usage cap.- Review your current limits on the Usage page.
- Implement exponential backoff and retry logic in your application.
- Contact support to request a limit increase if needed.
500 Provider Error
The upstream LLM provider returned an error or was unavailable.- TokenHub automatically retries with a backup provider when one is configured. See Fallback Routing to set this up.
- If the error persists, check the TokenHub status page for active provider incidents.
- The response body includes a
providerfield indicating which provider failed, which can help with debugging.