Skip to content

Python and JavaScript SDKs

Use the official OpenAI Python or JavaScript SDK with the CHUA ONE base URL, project key, exact model slug, streaming, and safe retry controls.

Before copying an example

  1. Create a server-side project key and store it in CHUA_API_KEY. Never expose the key in browser code.
  2. Call GET /v1/models with that key and copy an exact published model slug. The examples use gpt-5.4.
  3. Install the official package: pip install openai or npm install openai.

Python

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["CHUA_API_KEY"],
    base_url="https://chuaone.si/v1",
    max_retries=0,
)

response = client.chat.completions.create(
    model="gpt-5.4",
    messages=[{"role": "user", "content": "Explain what an API is in one sentence."}],
    max_tokens=128,
    extra_headers={"Idempotency-Key": "YOUR_UNIQUE_REQUEST_ID"},
)

print(response.choices[0].message.content)
print(response.usage)

This sends one Chat Completions request. Save the X-CHUA-Request-ID response header in your HTTP observability layer when you need a billing or delivery receipt.

JavaScript / TypeScript

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.CHUA_API_KEY,
  baseURL: "https://chuaone.si/v1",
  maxRetries: 0,
});

const response = await client.chat.completions.create(
  {
    model: "gpt-5.4",
    messages: [{ role: "user", content: "Explain what an API is in one sentence." }],
    max_tokens: 128,
  },
  { headers: { "Idempotency-Key": "YOUR_UNIQUE_REQUEST_ID" } },
);

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

JavaScript streaming

const stream = await client.chat.completions.create(
  {
    model: "gpt-5.4",
    messages: [{ role: "user", content: "Write one short sentence." }],
    max_tokens: 128,
    stream: true,
  },
  { headers: { "Idempotency-Key": "YOUR_UNIQUE_REQUEST_ID" } },
);

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

Use stream only when the selected model reports streaming support. A failure can arrive after HTTP 200 as an SSE error event; treat partial text as incomplete.

Retry and compatibility rules

  • The examples disable automatic SDK retries. Retry only when CHUA ONE explicitly marks the error retryable or returns Retry-After, and reuse the same Idempotency-Key only for the identical request.
  • The OpenAI SDK is a transport client here. Only the request fields documented by CHUA ONE are accepted; unsupported OpenAI features are not implied.

Related guides

Authentication · Chat Completions · Responses · Messages · Errors and retries