Yaha AI Gateway
SDK Guides

OpenAI Python

Configure the OpenAI Python SDK to use Yaha Gateway.

Install the official SDK:

pip install openai

Basic usage

from openai import OpenAI

client = OpenAI(
    base_url="https://gateway.yahagateway.io/v1",
    api_key="yaha.YOUR_PROJECT_KEY",
)

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello from Yaha"}],
)

print(response.choices[0].message.content)

Streaming

stream = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello"}],
    stream=True,
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

Environment variables

You can also configure via env vars (SDK default):

export OPENAI_BASE_URL="https://gateway.yahagateway.io/v1"
export OPENAI_API_KEY="yaha.YOUR_PROJECT_KEY"
from openai import OpenAI

client = OpenAI()  # reads OPENAI_BASE_URL and OPENAI_API_KEY

Notes

  • Use your full yaha.* key as api_key, not an OpenAI provider key.
  • Pick a model on your project allowlist.
  • For coding agents (Claude Code, Codex, etc.), see Integrations.
  • For more languages and a reusable integration prompt, see Language examples.

On this page