Mixedbread

Python

Introduction

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

Installation

Installation
pip install mixedbread

Quick Start

Get started with a simple example:

Basic Usage
import os
from mixedbread import Mixedbread

mxbai = Mixedbread(api_key=os.getenv("MIXEDBREAD_API_KEY"))

vector_store = mxbai.vector_stores.create(
    name='my-knowledge-base',
    description='Product documentation and guides'
)

print(f"Created vector store: {vector_store.id}")

Configuration

The Mixedbread constructor accepts the following parameters:

class Mixedbread:
    def __init__(
        self,
        api_key: str,
        max_retries: int = 3,
        timeout: float = 30.0,
        base_url: str = "https://api.mixedbread.com"
    ):
        # ...
  • api_key: Your Mixedbread API key (required)
  • max_retries: Maximum number of retries for failed requests (default: 3)
  • timeout: Request timeout in seconds (default: 30.0)
  • base_url: Custom base URL for API requests (default: )

Async Support

For async applications, use the async client:

Async client
from mixedbread import AsyncMixedbread

async_mxbai = AsyncMixedbread(api_key="YOUR_API_KEY")

Error Handling

Use try/except blocks to handle errors:

from mixedbread.exceptions import MixedbreadError, RateLimitError

try:
    results = mxbai.vector_stores.search(
        query="How does authentication work?",
        vector_store_identifiers=["your-vector-store-id"],
        top_k=5,
        search_options={
            'return_metadata': True,
            'rerank': True
        }
    )
    
    for chunk in results.data:
        print(f"Score: {chunk.score:.4f}, File: {chunk.filename}")
        print(f"Content: {chunk.text}\n")
        
except RateLimitError as e:
    print(f"Rate limit exceeded. Retry after {e.retry_after} seconds")
except MixedbreadError as e:
    print(f"API Error: {e}")
    print(f"Status Code: {e.status_code}")
except Exception as e:
    print(f"Unexpected error: {e}")

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 Initialization
import os
from mixedbread import Mixedbread

mxbai = Mixedbread()

mxbai = Mixedbread(
    api_key=os.getenv("MXBAI_API_KEY"),
    base_url=os.getenv("MIXEDBREAD_BASE_URL", "https://api.mixedbread.com")
)

Last updated: August 19, 2025