Chat

Generate stateless multilingual assistant responses with the synchronous or asynchronous Python client.

Synchronous client

Pass a single prompt string to client.chat():

import os
import orbitalsai
 
client = orbitalsai.Client(api_key=os.environ["ORBITALSAI_API_KEY"])
 
response = client.chat("Sannu, yaya kake?")
 
print(response.text)
print(f"Cost: ${response.usage.cost:.6f}")
print(f"Tokens used: {response.usage.total_tokens}")

response.text is a convenience property returning the assistant's reply string. The full ChatMessage is also available via response.message or response.choices[0].message.

Multi-turn conversations

OrbitalsAI chat completions are stateless. Provide the full conversation history alternating between user and assistant turns, starting and ending with user:

response = client.chat(
    messages=[
        {"role": "user", "content": "Ina so in buɗe asusun ajiya."},
        {"role": "assistant", "content": "Muna maraba! Wane irin asusu kake so ka buɗe?"},
        {"role": "user", "content": "Asusun kasuwanci nake so."},
    ],
    max_tokens=300,
)
 
print(response.text)

You can also pass a list of ChatMessage objects:

from orbitalsai import ChatMessage
 
messages = [
    ChatMessage(role="user", content="Good morning."),
    ChatMessage(role="assistant", content="Good morning! How can I assist you today?"),
    ChatMessage(role="user", content="Can you translate 'hello' into Swahili?"),
]
 
response = client.chat(messages)
print(response.text)

System instructions

Pass instructions to establish application context and model behavior:

response = client.chat(
    "How do I check my monthly statement?",
    instructions="You are a helpful customer service assistant for an African digital bank. Always be polite, concise, and professional.",
    max_tokens=256,
)
 
print(response.text)

Async client

For asynchronous applications, use AsyncClient:

import os
import asyncio
import orbitalsai
 
async def main():
    async with orbitalsai.AsyncClient(
        api_key=os.environ["ORBITALSAI_API_KEY"]
    ) as client:
        response = await client.chat(
            "Ẹ ku owuro, bawo ni nkan?",
            max_tokens=200,
        )
        print(response.text)
        print(response.usage.total_tokens)
 
asyncio.run(main())

Response fields

ChatCompletion provides both convenience shortcuts and standard OpenAI-compatible fields:

  • response.text: Assistant reply text (str).
  • response.message: ChatMessage(role="assistant", content=...).
  • response.choices: List of ChatChoice items (with index, message, finish_reason).
  • response.usage: ChatUsage with prompt_tokens, completion_tokens, total_tokens, and cost.
  • response.model: Model identifier ("Perigee-1-text").
  • response.id: Unique completion ID.

See the Chat guide, Chat API reference, and Errors and limits.

On this page