JavaScript SDK
Use the official OpenAI Node SDK and point it at CloudService. Model IDs come from the models and pricing page, and every request field is listed in Chat Completions.
Set CLOUDSERVICE_BASE_URL to https://api.yourdomain.example/v1 for API credit or https://api.yourdomain.example/token/v1 for an API-token key. This is the OpenAI-compatible route; native Claude apps use their origin-only setup instead.
bash
# API-credit key:
export CLOUDSERVICE_BASE_URL="https://api.yourdomain.example/v1"
# API-token key:
# export CLOUDSERVICE_BASE_URL="https://api.yourdomain.example/token/v1"Install
bash
npm install openaiBasic chat
client.ts
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.CLOUDSERVICE_API_KEY,
baseURL: process.env.CLOUDSERVICE_BASE_URL,
});
const response = await client.chat.completions.create({
model: "YOUR_AUTHENTICATED_MODEL_ID",
messages: [{ role: "user", content: "Write a haiku about fast inference." }],
});
console.log(response.choices[0]?.message?.content);Streaming
stream.ts
const stream = await client.chat.completions.create({
model: "YOUR_AUTHENTICATED_MODEL_ID",
messages: [{ role: "user", content: "Stream a short greeting." }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}Server-sent-event framing and safe disconnect handling are covered in Streaming. The same flow in other languages: Python, cURL.