Node.js
Use the OpenAI JavaScript SDK with Divyam's Chat Completions endpoint. Run it in a trusted Node.js backend so your API key stays private.
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
Use Node.js 22 or 24 LTS. In your project folder, run:
npm 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.mjs in your project folder:
import OpenAI from 'openai'
const client = new OpenAI({
apiKey: process.env.DIVYAM_API_KEY,
baseURL: process.env.DIVYAM_BASE_URL,
})
const response = await client.chat.completions.create({
model: process.env.DIVYAM_MODEL,
messages: [{ role: 'user', content: 'Say hello in one sentence.' }],
})
console.log(response.choices[0].message.content)
Run it:
node first-request.mjs
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 the configured model ID on every request. Picking a model in the console doesn't change what your code sends.
Keep the SDK client and the key on your server. Your browser app should call your backend and never call Divyam with the key.
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.