Python SDK
The official SDKs work unchanged: you give them Kloria’s address and your key. Choose the SDK for the format you prefer, not for the model: Claude models accept both formats.
pip install openai anthropicThe examples read the key from KLORIA_API_KEY (see Quickstart).
Simple request
Section titled “Simple request”import osfrom openai import OpenAI
client = OpenAI( base_url="https://api.kloria.dev/v1", api_key=os.environ["KLORIA_API_KEY"],)
response = client.chat.completions.create( model="claude-sonnet-5", messages=[ {"role": "system", "content": "Answer briefly."}, {"role": "user", "content": "Explain what a webhook is."}, ],)
print(response.choices[0].message.content)print(response.usage) # billed input and output tokensimport osimport anthropic
client = anthropic.Anthropic( base_url="https://api.kloria.dev", # no /v1 api_key=os.environ["KLORIA_API_KEY"],)
message = client.messages.create( model="claude-sonnet-5", max_tokens=1024, system="Answer briefly.", messages=[{"role": "user", "content": "Explain what a webhook is."}],)
print(message.content[0].text)print(message.usage)Streaming
Section titled “Streaming”To print the answer as it’s generated:
stream = client.chat.completions.create( model="gpt-6.1-sol", messages=[{"role": "user", "content": "Write a haiku about Git."}], stream=True,)
for chunk in stream: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True)with client.messages.stream( model="claude-sonnet-5", max_tokens=1024, messages=[{"role": "user", "content": "Write a haiku about Git."}],) as stream: for text in stream.text_stream: print(text, end="", flush=True)Environment variables the SDKs read
Section titled “Environment variables the SDKs read”Both SDKs can read their configuration from the environment. If you set these, you can create the client without arguments:
| SDK | Address | Key |
|---|---|---|
| OpenAI | OPENAI_BASE_URL=https://api.kloria.dev/v1 |
OPENAI_API_KEY |
| Anthropic | ANTHROPIC_BASE_URL=https://api.kloria.dev |
ANTHROPIC_API_KEY |
Handling errors
Section titled “Handling errors”The SDKs raise a typed exception per HTTP status. The most common ones with Kloria:
import openai
try: response = client.chat.completions.create(model="claude-sonnet-5", messages=[...])except openai.AuthenticationError: ... # 401: key invalid, disabled or expiredexcept openai.PermissionDeniedError: ... # 403: balance used up, key quota reached, or model not allowed for this keyexcept openai.RateLimitError: ... # 429: too many requests, retry after a pauseexcept openai.APIStatusError as e: print(e.status_code, e.message)Each status is detailed in the API reference.
© 2026 Kloria — private beta