Skip to main content

Getting started

  1. Install
  2. Set your API key
  3. Send a chat completion
  4. See it in the Portal

Install

Install the Maitai SDK:
pip install maitai-python

Set your API key

export MAITAI_API_KEY="<YOUR_MAITAI_API_KEY>"
See Authentication for other options (provider keys, Portal-managed keys).

Send a chat completion

Implementing Maitai into your application requires minimal code changes.
import maitai

maitai_client = maitai.MaitaiAsync()

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

response = await maitai_client.chat.completions.create(
    messages=messages,
    model="llama3-70b-8192",  # Optional: omit to use your Portal config
    application="YOUR_APPLICATION",  # Groups traffic in the Portal (auto-created on first use)
    intent="CONVERSATION",  # Also called action_type (auto-created on first use)
    session_id="YOUR_SESSION_ID",  # Recommended for grouping requests into sessions
    metadata={},  # Optional: custom tags for filtering/debugging
)
session_id is optional (the SDK will generate one if you omit it), but you’ll get the best Portal experience if you provide a stable session id per user/session.
The full implementation reference can be found here: Chat.

See it in the Portal

Run your application, make sure it makes at least one chat completion request, then head over to portal.trymaitai.ai and inspect the new Application/Intent resources and requests.

Next Steps

  • Tune configuration in the Portal: Configuration
  • Add domain context to improve responses: upload application context entries in the Portal (Application → Edit → Add Context Entry)
  • Build a regression suite: Test Sets
  • Optional: set up alerts in the Portal (SettingsNotifications)