> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trymaitai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Base URL

> Integrate Maitai with your existing OpenAI SDK implementation by changing the base URL and adding a few headers.

<Note>
  While using the OpenAI SDK is possible, we recommend using the [Maitai SDK](/get_started/quickstart) for the best experience and full access to all features.
</Note>

## 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.

<CodeGroup>
  ```python Python theme={null}
  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.com
  )

  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"
      }
  )
  ```

  ```javascript Node theme={null}
  import OpenAI from "openai";

  // Initialize the client with Maitai's base URL
  const openai = new OpenAI({
    baseURL: "https://api.trymaitai.ai",
    apiKey: "YOUR_MAITAI_API_KEY",  // Get this from portal.trymaitai.com
  });

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

  const response = await openai.chat.completions.create(
    {
      model: "gpt-4o",  // Use any supported model
      messages: messages,
    },
    {
      headers: {  // Required Maitai headers
        "X-Maitai-Application": "YOUR_APPLICATION",
        "X-Maitai-Intent": "CONVERSATION",
        "X-Maitai-Session-Id": "YOUR_SESSION_ID"
      }
    }
  );
  ```
</CodeGroup>

## Limitations

<Warning>
  **Base URL approach tradeoffs**

  The 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.
</Warning>

## Authentication with Base URL Approach

You can provide provider keys through headers:

<CodeGroup>
  ```python Python theme={null}
  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"
      }
  )
  ```

  ```javascript Node theme={null}
  import OpenAI from "openai";

  const openai = new OpenAI({
      baseURL: "https://api.trymaitai.ai",
      apiKey: "YOUR_MAITAI_API_KEY"
  });

  const response = await openai.chat.completions.create(
    {
      model: "gpt-4o",
      messages: [{ role: "user", content: "Hello!" }],
    },
    {
      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"
      }
    }
  );
  ```
</CodeGroup>
