OpenAI Compatibility#

saia_python.create_openai_client(*, api_key: str | None = None, base_url: str | None = None, key_file: str | None = None, async_client: bool = False)[source]#

Create an OpenAI client configured for the SAIA platform.

Reuses the same credential and base URL resolution as SAIAClient: environment variables, .env, .saia_api, and config.toml are checked automatically when parameters are omitted.

Parameters:
  • api_key – Explicit API key. If omitted, resolved via load_api_key().

  • base_url – Explicit base URL. If omitted, resolved via resolve_base_url().

  • key_file – Path to a .saia_api or .env file. Ignored when api_key is provided.

  • async_client – If True, return an openai.AsyncOpenAI instance instead of openai.OpenAI.

Returns:

An openai.OpenAI or openai.AsyncOpenAI instance.

Example:

from saia_python import create_openai_client

client = create_openai_client()
response = client.chat.completions.create(
    model="llama-3.3-70b-instruct",
    messages=[{"role": "user", "content": "Hello!"}],
)

# Embeddings
embedding = client.embeddings.create(
    model="e5-mistral-7b-instruct",
    input="Text to embed",
)