Routara
OPENAI SDK · PYTHON / PRACTICAL GUIDE

Use the OpenAI Python SDK with Routara

If your application already calls chat.completions, you can keep the Python SDK and request shape. Use a Routara API key, the Routara base URL, and a model ID available in the live catalog. This guide sends one small request so you can check the response before moving production traffic.

01

Install the SDK and store your key

Use a virtual environment in your application. Set ROUTARA_API_KEY in your shell or secret manager; do not put the full key in a repository.

python -m pip install --upgrade openai
export ROUTARA_API_KEY="your-key"
02

Send one request

The example uses alibaba-qwen-turbo, a low-cost text model. Check the live catalog before changing models; availability and price can change.

import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["ROUTARA_API_KEY"], base_url="https://api.routara.ai/v1")
response = client.chat.completions.create(
    model="alibaba-qwen-turbo",
    messages=[{"role": "user", "content": "Reply with one short integration tip."}],
    max_tokens=64,
)
print(response.id, response.model, response.usage)
print(response.choices[0].message.content)
03

Check the result before migrating

A successful call returns a response ID, a model, usage, and assistant text. A 401 means the key or Authorization header is wrong. A 403 can mean account or regional policy. If the account has no eligible trial credit, add wallet funds before retrying; do not loop on a billing error.

Before you ship

  • Start with one request and a low max_tokens value.
  • Record the response ID when contacting support; never send your key.
  • Compare the model and cost shown in your Routara account before sending production traffic.