Node.js SDK
npm install and chat in 5 lines
Quickstart: Node.js SDK
Go from zero to working chat in 5 lines of JavaScript.
### Install the SDK ```bash npm install @archipelag/sdk ``` ### Send a chat request ```javascript import { Archipelag } from "@archipelag/sdk"; const client = new Archipelag({ apiKey: "your-api-key-here" }); const result = await client.chat("Say hello in three languages"); console.log(result.content); ``` ### Run it ```bash export ARCHIPELAG_API_KEY="your-api-key-here" node hello.mjs ``` ``` Hello! (English) Bonjour! (French) Hola! (Spanish) ```
Using the response
client.chat() returns a ChatResult with these fields:
const result = await client.chat("Say hello in three languages");
result.content; // "Hello! (English)\nBonjour!..."
result.jobId; // "550e8400-e29b-41d4-a716-446655440000"
result.finishReason; // "stop"
result.usage.promptTokens; // 12
result.usage.completionTokens; // 18
result.usage.totalTokens; // 30
result.usage.creditsUsed; // 0.001
Streaming
Use client.chatStream() with callbacks for real-time token delivery:
import { Archipelag } from "@archipelag/sdk";
const client = new Archipelag({ apiKey: "your-api-key-here" });
await client.chatStream("Say hello in three languages", {
onToken: (token) => process.stdout.write(token),
onDone: (usage) => {
console.log(); // newline
console.log(`Tokens used: ${usage.totalTokens}`);
},
});
Options
Both methods accept an options object:
const result = await client.chat("Translate 'hello world' to Japanese", {
systemPrompt: "You are a helpful translator.",
maxTokens: 256,
temperature: 0.3,
workload: "llm-chat", // default
});
Environment variable
The client reads ARCHIPELAG_API_KEY automatically if no apiKey is passed:
// Uses ARCHIPELAG_API_KEY from environment
const client = new Archipelag();
Next steps
- Python SDK quickstart — same experience in Python
- OpenAI-compatible quickstart — use your existing OpenAI code
- User Guide — models, pricing, error handling
