Skip to main content
While using the OpenAI SDK is possible, we recommend using the Maitai SDK for the best experience and full access to all features.

Configure OpenAI SDK

You can use Maitai with your existing OpenAI SDK implementation by changing the base URL to point to Maitai’s API endpoint, and adding the required headers.
import openai

# Initialize the client with Maitai's base URL
client = openai.OpenAI(
    base_url="https://api.trymaitai.ai",
    api_key="YOUR_MAITAI_API_KEY"  # Get this from portal.trymaitai.ai
)

messages = [
    {"role": "system", "content": "You are a helpful ordering assistant..."},
    {"role": "user", "content": "Generate a response to the customer..."},
]

response = client.chat.completions.create(
    model="gpt-4o",  # Use any supported model
    messages=messages,
    extra_headers={  # Required Maitai headers
        "X-Maitai-Application": "YOUR_APPLICATION",
        "X-Maitai-Intent": "CONVERSATION",
        "X-Maitai-Session-Id": "YOUR_SESSION_ID"
    }
)

Limitations

Base URL approach tradeoffsThe Base URL approach is great for drop-in compatibility, but it’s an OpenAI-style client talking to Maitai’s API. You won’t get some Maitai SDK conveniences (like callback handling for evaluations, client-side inference/store-only modes, and context management helpers).If you want the full Maitai feature set and the cleanest ergonomics, use the native Maitai SDK.

Authentication with Base URL Approach

You can provide provider keys through headers:
import openai

client = openai.OpenAI(
    base_url="https://api.trymaitai.ai",
    api_key="YOUR_MAITAI_API_KEY"
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
    extra_headers={
        # Required Maitai headers
        "X-Maitai-Application": "YOUR_APPLICATION",
        "X-Maitai-Intent": "CONVERSATION",
        "X-Maitai-Session-Id": "YOUR_SESSION_ID",
        
        # Provider authentication headers (optional)
        "X-Maitai-Auth-OpenAI": "YOUR_OPENAI_API_KEY",
        "X-Maitai-Auth-Anthropic": "YOUR_ANTHROPIC_API_KEY",
        "X-Maitai-Auth-Groq": "YOUR_GROQ_API_KEY",
        "X-Maitai-Auth-Gemini": "YOUR_GEMINI_API_KEY",
        "X-Maitai-Auth-Azure": "YOUR_AZURE_API_KEY",
        "X-Maitai-Auth-Sambanova": "YOUR_SAMBANOVA_API_KEY"
    }
)