Python
Use the OpenAI Python SDK with Divyam's Chat Completions endpoint. You only change the base URL, the API key and the model.
You need a Divyam account and an API key. If you don't have them yet, follow Getting Started first.
Replace the shortened divyam-sw-v1-... shown in examples with your complete API key.
The examples use divyam-as/gpt-6-sol. For another model, select its current ID in your harness or copy it from Models and pricing, and check its context limit and supported features.
Install the SDK
The OpenAI Python SDK needs Python 3.10 or later. In your application's Python environment, run:
python3 -m pip install openai
Set your connection
In Bash, run:
export DIVYAM_BASE_URL='https://api.preview.divyam.ai/v1'
export DIVYAM_MODEL='divyam-as/gpt-6-sol'
read -rsp 'Divyam API key: ' DIVYAM_API_KEY
printf '\n'
export DIVYAM_API_KEY
Paste your key at the prompt and press Enter. It stays hidden. Run the example from this terminal, because a new terminal needs the variables set again. In a deployed application, use your existing secret and environment settings instead.
Send a request
Save this as first_request.py:
"""Send a first Chat Completions request through Divyam."""
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["DIVYAM_API_KEY"],
base_url=os.environ["DIVYAM_BASE_URL"],
)
response = client.chat.completions.create(
model=os.environ["DIVYAM_MODEL"],
messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(response.choices[0].message.content)
Run it:
python3 first_request.py
The answer prints in your terminal.
Connect your application
Use the same client settings in the backend code that calls the model. Keep your own messages, conversation history and tool-result handling, and send DIVYAM_MODEL as the model on every request. Picking a model in the console doesn't change what your code sends.
For an async backend, create AsyncOpenAI with the same api_key and base_url, and await client.chat.completions.create(...).
Divyam uses the Chat Completions API. Code built on the Responses API or native Anthropic Messages needs to move to client.chat.completions.
Check your requests
Open the Divyam console and select Logs. Your requests appear there within a few seconds, newest first, with their status, token counts and latency. Usage and Credits & Billing catch up within a few minutes.
Some clients display zero when model prices are missing. Check Credits & Billing for Divyam charges. Local dollar limits depend on the client's price and usage data.
For filters, cached-token counts and the requested-versus-routed view, see Logs and usage.
For errors, see Troubleshooting. To replace a key, see API keys.