DivyamSetup guides Open console

Integrate Node.js with Divyam

Use the OpenAI JavaScript SDK with Divyam’s Chat Completions endpoint. Run this code in a trusted Node.js backend, where your API key stays private.

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.

Install the SDK

Use Node.js 22 or 24 LTS, supported by the current OpenAI JavaScript SDK. In your application’s project directory, run:

npm install openai

This installs the SDK locally for the project.

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.mjs in the project directory:

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)
node first-request.mjs

You should see an answer in the terminal. Record the request time and find it in Divyam Logs.

Connect your application

Use this client configuration in the backend that makes your application’s model requests. Replace the example message with your application’s messages. Preserve conversation history and tool-result handling. Send the configured model ID on every request. Selecting a model in the console does not change your backend.

Keep the SDK client and Divyam key on the server. Your browser application should call your backend rather than expose the credential to users.

Run the application workflow tests. Verify tools, streaming, and conversation continuations when your application uses them. Review usage and rotate credentials using the rotation guide.

Resolve failures

Use the HTTP status and error message with Troubleshooting. This guide uses Chat Completions. Applications using Responses or native Anthropic Messages require a separate compatibility check.