Mixedbread

TypeScript

Introduction

The Mixedbread TypeScript SDK provides a convenient interface for accessing our API with built-in error handling, retries, and type safety.

Installation

Installation
npm install @mixedbread/sdk

Quick Start

Get started with a simple example:

Basic Usage
import { Mixedbread } from "@mixedbread/sdk";

const mxbai = new Mixedbread({
    apiKey: process.env.MIXEDBREAD_API_KEY!,
});

const vectorStore = await mxbai.vectorStores.create({
    name: 'my-knowledge-base',
    description: 'Product documentation and guides'
});

console.log(`Created vector store: ${vectorStore.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: )

Error Handling

Use try/catch blocks to handle errors:

import { MixedbreadError, RateLimitError } from "@mixedbread/sdk";

try {
    const results = await mxbai.vectorStores.search({
        query: "How does authentication work?",
        vector_store_identifiers: ["your-vector-store-id"],
        top_k: 5,
        search_options: {
            return_metadata: true,
            rerank: true
        }
    });
    
    for (const chunk of results.data) {
        console.log(`Score: ${chunk.score.toFixed(4)}, File: ${chunk.filename}`);
        console.log(`Content: ${chunk.text}\n`);
    }
} 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

Environment Configuration
export MXBAI_API_KEY="your_api_key_here"

export MIXEDBREAD_BASE_URL="https://api.mixedbread.com"
Environment-based Configuration
import { Mixedbread } from "@mixedbread/sdk";

const mxbai = new Mixedbread({
    apiKey: process.env.MXBAI_API_KEY!,
    baseURL: process.env.MIXEDBREAD_BASE_URL,
});

if (!process.env.MXBAI_API_KEY) {
    throw new Error("MXBAI_API_KEY environment variable is required");
}

Last updated: September 10, 2025