Quickstart
SDK Quickstart
Go from an empty project to your first Xpectrum response in a few minutes. The SDK gives your server a simple way to call chat, keep user context, and grow into workflows and voice.
What you will build
This guide creates a small server-side chat client. It sends a message for one user, prints the answer, and leaves room for streaming and conversation history when you are ready.
1. Create an API key
Create a Xpectrum workspace and API key in the dashboard. Keep the key private: it should live in your server environment, never in a browser bundle or public repository.
export XPECTRUM_API_KEY="xpectrum_XXXXXXXXXXXXXXXX"2. Install the SDK
npm install xpectrumThe SDK talks to the same OpenAI-compatible API underneath, so you can also start with plain HTTP or an OpenAI client and add the SDK as your application becomes more involved.
3. Send your first message
import { XpectrumChat } from "xpectrum";
const chat = new XpectrumChat({
baseUrl: "https://cloud.xpectrum.dev/v1",
apiKey: process.env.XPECTRUM_API_KEY!,
user: "user-123",
});
const response = await chat.send("Give me a one-sentence summary of our support queue.");
console.log(response.content);4. Stream a response
Streaming lets your interface show the answer as it arrives instead of waiting for the complete response.
const stream = await chat.stream("Draft a reply to this customer message.");
for await (const chunk of stream) {
process.stdout.write(chunk.content ?? "");
}5. Put it behind your app server
Your browser should call your own application route. That route reads the secret key from the environment and calls Xpectrum on the user's behalf.
// app/api/chat/route.ts
import { XpectrumChat } from "xpectrum";
export async function POST(request: Request) {
const { message, userId } = await request.json();
const chat = new XpectrumChat({
baseUrl: "https://cloud.xpectrum.dev/v1",
apiKey: process.env.XPECTRUM_API_KEY!,
user: userId,
});
const response = await chat.send(message);
return Response.json({ content: response.content });
}6. Keep building
Once the first request works, connect a knowledge base, add a workflow run, or give the experience a voice interface. The same API key and user context carry across those building blocks.
- Add chat streaming, vision, and message history
- Read and manage conversation threads
- Run a workflow with step-by-step progress
- Add a drop-in chat or voice widget
Common first questions
Can I use another language?
Yes. Xpectrum exposes HTTP endpoints with an OpenAI-compatible shape, so any language that can make authenticated requests can use it.
Can I call Xpectrum directly from the browser?
Only with a short-lived, server-issued credential. For most apps, keep the permanent API key in your server route.
Where do I see errors?
Start with the error reference. Errors use a predictable envelope and include an HTTP status that your route can pass on or translate for your UI.