TypeScript
Introduction
The Mixedbread TypeScript SDK provides a convenient interface for accessing our API with built-in error handling, retries, and type safety.
Installation
npm install @mixedbread/sdkQuick Start
Get started with a simple example:
import { Mixedbread } from "@mixedbread/sdk";
const mxbai = new Mixedbread({
apiKey: process.env.MXBAI_API_KEY!,
});
const store = await mxbai.stores.create({
name: 'my-knowledge-base',
description: 'Product documentation and guides'
});
console.log(`Created store: ${store.id}`);Configuration
The Mixedbread constructor accepts the following options:
interface MixedbreadOptions {
apiKey: string;
maxRetries?: number;
timeout?: number;
baseURL?: string;
}apiKey: Your Mixedbread API key (required)maxRetries: Maximum number of retries for failed requests (default: 3)timeout: Request timeout in milliseconds (default: 30000)baseURL: Custom base URL for API requests (default: https://api.mixedbread.com)
Error Handling
Use try/catch blocks to handle errors:
import { MixedbreadError, RateLimitError } from "@mixedbread/sdk";
try {
const results = await mxbai.stores.search({
query: "How does authentication work?",
store_identifiers: ["your-store-id"],
top_k: 5,
search_options: {
return_metadata: true,
rerank: true
}
});
for (const chunk of results.data) {
console.log(chunk);
}
} catch (err) {
if (err instanceof RateLimitError) {
console.error(`Rate limit exceeded. Retry after ${err.retryAfter} seconds`);
} else if (err instanceof MixedbreadError) {
console.error(`API Error: ${err.message}`);
console.error(`Status Code: ${err.statusCode}`);
} else {
console.error(`Unexpected error: ${err}`);
}
}Environment Setup
Using Environment Variables
export MXBAI_API_KEY="your_api_key_here"
export MXBAI_BASE_URL="https://api.mixedbread.com"import { Mixedbread } from "@mixedbread/sdk";
if (!process.env.MXBAI_API_KEY) {
throw new Error("MXBAI_API_KEY environment variable is required");
}
if (!process.env.MXBAI_BASE_URL) {
throw new Error("MXBAI_BASE_URL environment variable is required");
}
const mxbai = new Mixedbread({
apiKey: process.env.MXBAI_API_KEY,
baseURL: process.env.MXBAI_BASE_URL,
});Last updated: February 24, 2026