Integrate Python with Divyam
Use the OpenAI Python SDK with Divyam’s Chat Completions endpoint. Run a first request, then connect your application’s existing messages and workflow.
Prepare your account
Follow the console guide to sign in and create an API key.
Copy the base URL from Getting Started and an available ID from Models & Pricing.
The examples use https://api.demo.divyam.ai/v1 and divyam-as/gpt-5.6-sol.
Install the SDK
Use Python 3.10 or later, as required by the current OpenAI Python SDK. In your application’s Python environment, run:
python3 -m pip install openai
Set your connection
Run these commands in Bash. Substitute your copied base URL and model if they differ.
export DIVYAM_BASE_URL='https://api.demo.divyam.ai/v1'
export DIVYAM_MODEL='divyam-as/gpt-5.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 while you enter it. Run the example from this terminal. A new terminal needs these variables set again. For deployed applications, use your existing secret and environment configuration.
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)
python3 first_request.py
You should see an answer in the terminal. Record the request time and find it in Divyam Logs.
Connect your application
Use the same client configuration in the backend that makes your application’s model requests.
Replace the example message with your application’s messages. Preserve your conversation and tool-result handling.
Send DIVYAM_MODEL as the request’s model rather than relying on the console selection.
For an asynchronous backend, use AsyncOpenAI with the same api_key and base_url arguments.
Await client.chat.completions.create(...) within your application’s existing asynchronous flow.
Run the application workflow tests, including tools or streaming when your application uses them. Check recorded requests and spend for the intended catalog model. Rotate credentials using the rotation guide.
Resolve failures
Use the HTTP status and error message with Troubleshooting. Do not retry credit exhaustion without resolving the account restriction. This guide uses Chat Completions. Applications using Responses or native Anthropic Messages require a separate compatibility check.