Mixedbread

Python SDK

Introduction

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

Installation

Install the SDK using pip:

Installation
pip install mixedbread

For development with the latest features:

Development Installation
pip install mixedbread[dev]

Quick Start

Get started with a simple example:

Basic Usage
import os
from mixedbread import Mixedbread
 
# Initialize client with API key
mxbai = Mixedbread(api_key=os.getenv("MIXEDBREAD_API_KEY"))
 
# Generate embeddings
embeddings = mxbai.embed(
    model="mixedbread-ai/mxbai-embed-large-v1",
    input=["Hello, world!", "How are you?"]
)
 
print(f"Generated {len(embeddings.data)} embeddings")

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:
    embeddings = mxbai.embed(
        model="mixedbread-ai/mxbai-embed-large-v1",
        input=["Example text"]
    )
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}")

Available Services

The SDK provides access to all Mixedbread API endpoints:

ServiceDescriptionExample Usage
mxbai.embed()Generate text embeddingsmxbai.embed(model="...", input=["text"])
mxbai.rerank()Rerank document listsmxbai.rerank(query="...", documents=[...])
mxbai.vector_storesManage vector storesmxbai.vector_stores.create(name="...")
mxbai.vector_stores.filesManage store filesmxbai.vector_stores.files.create(...)
mxbai.filesUpload and manage filesmxbai.files.create(file=file_obj)
mxbai.parsing.jobsParse documentsmxbai.parsing.jobs.create(file_id="...")

Environment Setup

Using Environment Variables

Environment Configuration
# Set your API key
export MIXEDBREAD_API_KEY="your_api_key_here"
 
# Optional: Custom base URL
export MIXEDBREAD_BASE_URL="https://api.mixedbread.com"
Environment-based Initialization
import os
from mixedbread import Mixedbread
 
# Automatically uses MIXEDBREAD_API_KEY environment variable
mxbai = Mixedbread()
 
# Or specify explicitly
mxbai = Mixedbread(
    api_key=os.getenv("MIXEDBREAD_API_KEY"),
    base_url=os.getenv("MIXEDBREAD_BASE_URL", "https://api.mixedbread.com")
)

Resources

Documentation

Support

Happy building with Python! 🐍🍞

Last updated: June 11, 2025