Python
The official openai and anthropic Python clients.
There is no Top Billing SDK to install: the official openai and anthropic Python packages work with a base URL change.
pip install openai anthropic
Chat
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)
Embeddings
vectors = client.embeddings.create(model="<embedding-model-id>", input=["first text", "second text"])
print(len(vectors.data[0].embedding))
Messages
import anthropic
client = anthropic.Anthropic(api_key=os.environ["TB_API_KEY"], base_url="https://api.topbilling.in")
msg = client.messages.create(model="<model-id>", max_tokens=256, messages=[{"role": "user", "content": "Hello"}])
print(msg.content[0].text)
More detail: OpenAI SDK and Anthropic SDK.