Skip to main content

HTTP and curl

Send JSON straight to Divyam's Chat Completions endpoint, from curl or your own HTTP client.

Before you start

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.

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. These variables apply to commands you run from this terminal.

Send a request​

curl --silent --show-error --include \
"${DIVYAM_BASE_URL%/}/chat/completions" \
-H "Authorization: Bearer ${DIVYAM_API_KEY}" \
-H 'Content-Type: application/json' \
--data-binary @- <<JSON
{
"model": "${DIVYAM_MODEL}",
"messages": [{"role": "user", "content": "Say hello in one sentence."}]
}
JSON

You get an HTTP 200 status and a JSON body with the answer in choices[0].message.content. --include prints the response headers, including the status line. Check that line, because curl's exit status shows success even when the server returns an error.

Configure your HTTP client​

FieldValue
MethodPOST
URLhttps://api.preview.divyam.ai/v1/chat/completions
Authorization headerBearer, a space, then your Divyam API key
Content-Type headerapplication/json
JSON bodyYour model and your application's messages

Build the body with your HTTP client's JSON serializer, not with shell substitution. Keep the key in your backend or trusted settings.

Full URL here, base URL in SDKs

A direct HTTP client needs the full URL ending in /chat/completions. An OpenAI SDK's base URL setting takes https://api.preview.divyam.ai/v1 alone, because the SDK adds /chat/completions itself.

If your application streams, test its event-stream handling through your normal workflow.

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.

Local cost estimates

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 non-2xx responses, see Troubleshooting. To replace a key, see API keys.