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

mxbai = Mixedbread(api_key="YOUR_API_KEY")

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

print(f"Created store: {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.stores.search(
        query="How does authentication work?",
        store_identifiers=["your-store-id"],
        top_k=5,
        search_options={
            'return_metadata': True,
            'rerank': True
        }
    )
    
    for chunk in results.data:
        print(chunk)
       
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 MXBAI_BASE_URL="https://api.mixedbread.com"
Environment-based Initialization
from mixedbread import Mixedbread

mxbai = Mixedbread(
    api_key=os.getenv("MXBAI_API_KEY"),
    base_url=os.getenv("MXBAI_BASE_URL")
)
Last updated: November 4, 2025