Skip to content
All guides

Developers & integrations

API Integration Guide (OpenAI-Compatible)

Configure environment variables and integrate chat, vision, and retrieval endpoints via cURL, Python, and Node.js.

Updated 2026-11-26 · 3 min read

Unified OpenAI-Compatible Specification

The platform gateway implements the standard OpenAI-compatible HTTPS REST specification with Bearer token authentication. Existing services built with official OpenAI SDKs or standard frameworks migrate cleanly by updating base_url, api_key, and model.

CapabilityStandard EndpointMethodApplicable Categories
Text & vision chat/v1/chat/completionsPOSTText & chat, reasoning, coding, visual understanding
Semantic vectors/v1/embeddingsPOSTEmbeddings
Candidate reranking/v1/rerankPOSTReranking
Image generation/v1/images/generationsPOSTImage creation
Speech synthesis & ASR/v1/audio/speech · /v1/audio/transcriptionsPOSTSpeech & audio
Enabled model list/v1/modelsGETQuery live model identifiers enabled for your key

Authentication and Environment Variable Management

Every request requires an Authorization: Bearer ${API_KEY} header. Always inject credentials from a server-side environment variable or secret manager rather than hardcoding strings in source files:

  • API_BASE_URL: Published platform gateway URL (for example https://api.your-domain.example.com/v1).
  • API_KEY: Server-side secret token issued by the platform console.
  • MODEL_ID: Canonical model identifier listed in Models (such as deepseek-v3.2 or qwen4-max).

Python and Node.js SDK Examples

Configure explicit request timeouts and bounded retries when initializing your SDK client:

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["API_KEY"],
    base_url=os.environ["API_BASE_URL"],
    timeout=60.0,
    max_retries=2,
)

completion = client.chat.completions.create(
    model="qwen4-max",
    messages=[
        {"role": "system", "content": "You are a principal backend engineer."},
        {"role": "user", "content": "Give three practical timeout and circuit-breaker guidelines."},
    ],
    temperature=0.2,
    max_tokens=1024,
)

print(completion.choices[0].message.content)

In Node.js / TypeScript backend services, use the standard openai package:

import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env.API_KEY,
  baseURL: process.env.API_BASE_URL,
  timeout: 60_000,
  maxRetries: 2,
});

const response = await client.chat.completions.create({
  model: 'deepseek-v3.2',
  messages: [
    { role: 'system', content: 'Answer concisely with actionable engineering steps.' },
    { role: 'user', content: 'Explain common causes of database connection pool exhaustion.' },
  ],
});

console.log(response.choices[0]?.message.content);

Key Request and Response Fields

FieldDirectionProduction Notes
modelRequest (required)Canonical identifier from the catalog, e.g., deepseek-r1
messagesRequest (required)Ordered conversation array (system, user, assistant, tool)
streamRequest (optional)Set true for interactive UIs to stream SSE tokens
temperatureRequest (optional)Use 0.0–0.2 for deterministic tasks, 0.6–0.8 for creative drafting
idResponseUnique request trace identifier—retain this for support diagnostics
choices[0].finish_reasonResponsestop (complete), length (hit max_tokens), or tool_calls
usageResponseReports prompt_tokens, completion_tokens, and total_tokens

Production Security Checklist

  1. Proxy through your backend: Authenticate end users in your own backend before forwarding requests to the model gateway; never expose raw API keys to browsers.
  2. Redact logs: Strip Authorization headers and sensitive personal data from application logs.
  3. Handle transient errors: Implement bounded retries and rate-limit handling as documented in Error Codes, Rate Limits & Troubleshooting.