Quickstart

Quickstart

Send a first OpenAI-compatible request in five steps: create a LivRouter API key, add credits, choose an exact model ID from the model catalog, install an SDK, and call the shared endpoint.

1. Create a key and check credits

Sign in, create a key on the API keys page, and check your Wallet for available funds. Key limits and the selected billing preference also affect whether a generation request can run.

2. Set your environment

Choose your terminal and replace the model placeholder with an exact accessible ID. Environment variables below apply to the current terminal session.

bash
export OPENAI_API_KEY="your-livrouter-api-key"export LIVROUTER_MODEL="your-model-id"

Keep the key in a server-side environment variable. Do not paste it into browser code, a public repository, or a client-side app bundle. Use the shared endpoint below; request format stays the same as the OpenAI SDK.

3. Send your first request

Install the SDK with pip install openai for Python or npm install openai for JavaScript. The cURL example below uses Bash syntax; PowerShell users can use the SDK examples or the native request below.

python
from openai import OpenAIimport os client = OpenAI(    base_url="https://api.livrouter.com/v1",    api_key=os.environ["OPENAI_API_KEY"],) completion = client.chat.completions.create(    model=os.environ["LIVROUTER_MODEL"],    messages=[        {"role": "user", "content": "Write a short welcome message."}    ],) print(completion.choices[0].message.content)

Confirm the first response

A successful call returns HTTP 200 and a completion object. Read choices[0].message.content for the assistant text and inspect the usage fields when you are measuring cost. The response is only meaningful if the model ID is current and your account has available credits.

This simplified example shows the fields to inspect; actual IDs, model names, token counts, and finish reasons vary.

json
{  "id": "chatcmpl_example",  "choices": [{    "index": 0,    "message": {"role": "assistant", "content": "Welcome to LivRouter!"},    "finish_reason": "stop"  }],  "usage": {"prompt_tokens": 12, "completion_tokens": 6, "total_tokens": 18}}
cURL
curl -sS -w "\nHTTP %{http_code}\n" https://api.livrouter.com/v1/models \  -H "Authorization: Bearer $OPENAI_API_KEY"

Use the models response to verify that your key can reach the endpoint, then copy the exact id into LIVROUTER_MODEL. The catalog can change, so do not rely on an old model name from a tutorial or screenshot.

4. Verify usage and cost

Open Usage logs and find the request by time, key, and model. Compare the recorded tokens and charge with the model's current rate. Read Usage logs and Billing & credits for cache fields and billing sources.

Streaming responses

For interactive UIs, add stream: true and consume server-sent event chunks as they arrive. cURL needs -N to disable output buffering:

cURL
curl -N https://api.livrouter.com/v1/chat/completions \  -H "Content-Type: application/json" \  -H "Authorization: Bearer $OPENAI_API_KEY" \  -d '{    "model": "'"$LIVROUTER_MODEL"'",    "stream": true,    "messages": [{"role": "user", "content": "Stream a one-sentence status update."}]  }'

In Python, pass stream=True and iterate over the returned chunks. In JavaScript, pass stream: true and iterate the async stream. Accumulate text from each delta, and handle a terminated stream as an error rather than silently treating a partial answer as complete.

Common errors

  • 401 Unauthorized: check that the Authorization header is Bearer YOUR_KEY, the key belongs to LivRouter, and the key has not been revoked. Create or rotate keys on the API keys page.
  • 404 or invalid model: confirm the path is https://api.livrouter.com/v1/chat/completions and copy the exact model id from the current catalog. Model names are not interchangeable across gateways.
  • 429 or insufficient credits: slow down retries, check account credits and rate limits, and use exponential backoff. Do not retry a permanent model or authentication error.
  • Timeout or incomplete stream: reduce the prompt and requested output for the first test, set a client timeout appropriate for your workload, and retry only when your request is safe to repeat.
  • Context-length error: trim conversation history or choose a model whose catalog entry supports the required context window. Token limits are model-specific.

Next steps

After the first request, compare supported models and rates in the model directory, review plans and billing, and check endpoint guidance. For Anthropic SDK or Claude Code, use the Anthropic-compatible guide and its separate base URL rules.