Skip to contentSkip to content

5-minute quickstart

1. Set environment variables

Create an API key in the customer portal and inject it into your local environment. Never put a key in source code, shell history, logs, or screenshots.

bash
export API_KEY="inject from a secure source"
export API_BASE_URL="data API origin"
export MODEL="choose a value returned by /v1/models"

The data API uses Authorization: Bearer $API_KEY. Call /v1/models first to confirm which models your current entitlements allow, then run any example below.

2. Send a request

cURL

bash
#!/usr/bin/env bash
set -euo pipefail

: "${API_KEY:?Set API_KEY in your environment}"
: "${API_BASE_URL:?Set API_BASE_URL to the data API origin}"
: "${MODEL:?Set MODEL to a model listed by /v1/models}"

curl --fail-with-body --silent --show-error \
  "${API_BASE_URL}/v1/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  --data "{\"model\":\"${MODEL}\",\"messages\":[{\"role\":\"user\",\"content\":\"Reply with one short greeting.\"}]}"

Python standard library

python
import json
import os
import urllib.request

api_key = os.environ["API_KEY"]
base_url = os.environ["API_BASE_URL"].rstrip("/")
model = os.environ["MODEL"]
body = json.dumps({
    "model": model,
    "messages": [{"role": "user", "content": "Reply with one short greeting."}],
}).encode()
request = urllib.request.Request(
    f"{base_url}/v1/chat/completions",
    data=body,
    headers={"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"},
    method="POST",
)

with urllib.request.urlopen(request, timeout=30) as response:
    print(response.read().decode())

Node.js 18+

js
const apiKey = process.env.API_KEY
const baseURL = process.env.API_BASE_URL?.replace(/\/$/, '')
const model = process.env.MODEL

if (!apiKey || !baseURL || !model) {
  throw new Error('Set API_KEY, API_BASE_URL, and MODEL in the environment')
}

const response = await fetch(`${baseURL}/v1/chat/completions`, {
  method: 'POST',
  headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    model,
    messages: [{ role: 'user', content: 'Reply with one short greeting.' }],
  }),
  signal: AbortSignal.timeout(30_000),
})

if (!response.ok) throw new Error(`Request failed with HTTP ${response.status}`)
console.log(await response.json())

3. Inspect the result

Retain the X-Request-Id response header for troubleshooting, but do not log request or response bodies. Use /v1/balance for available balance and /v1/usage for aggregate usage in the current credential scope.

Next: authentication and key safety · error handling