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.
Copy
Ask AI
import openai# Initialize the client with Maitai's base URLclient = 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" })
Downsides of the Base URL ApproachWhile using the base URL approach is simpler for existing OpenAI integrations, you’ll miss out on key Maitai features:
No Automatic Fallbacks: If your selected provider is unavailable, requests will fail instead of automatically falling back to another provider. Native SDK users can configure fallback behavior for maximum reliability.
No Configuration Management: You’ll need to hardcode model selection in your code instead of using Maitai’s centralized configuration management to dynamically select models based on rules.
For production applications, we recommend using the native Maitai SDK.