OpenAI SDK

Point the official OpenAI SDK at Top Billing.

Point the official SDK at https://api.topbilling.in/v1.

Python

python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["TB_API_KEY"], base_url="https://api.topbilling.in/v1")
resp = client.chat.completions.create(
    model="<model-id>",
    messages=[{"role": "user", "content": "Hello from Python"}],
)
print(resp.choices[0].message.content)

# streaming
for chunk in client.chat.completions.create(model="<model-id>", messages=[{"role": "user", "content": "Stream"}], stream=True, stream_options={"include_usage": True}):
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

JavaScript / TypeScript

typescript
import OpenAI from 'openai';

const client = new OpenAI({ apiKey: process.env.TB_API_KEY, baseURL: 'https://api.topbilling.in/v1' });
const resp = await client.chat.completions.create({ model: '<model-id>', messages: [{ role: 'user', content: 'Hello from Node' }] });
console.log(resp.choices[0].message.content);

Errors surface as the SDK’s usual exception classes; read error.code and the x-request-id header from error.headers.

What is compatible

Chat Completions, Embeddings and Models, with the parameters listed in the API reference. Parameters a model cannot honour return a clear 400; they are never silently ignored.