Skip to content

Python OpenAI SDK ​

The official OpenAI Python SDK works against Corveil unchanged — point base_url at your Corveil host and use a Corveil virtual API key.

Mode ​

Direct mode only. The SDK sends your Corveil key as the standard Authorization header.

1. Install ​

bash
pip install openai

2. Minimal example ​

python
from openai import OpenAI

client = OpenAI(
    base_url="https://your-corveil-host/v1",
    api_key="sk-citadel-your-key-here",
)

resp = client.chat.completions.create(
    model="or-claude-haiku-4.5",
    messages=[{"role": "user", "content": "Hello from Corveil"}],
)
print(resp.choices[0].message.content)

emb = client.embeddings.create(
    model="openai/text-embedding-3-small",
    input=["Hello from Corveil"],
)
print(emb.data[0].embedding[:3])

An org admin enables the embedding model under AI Gateway → Providers → Catalog before the embeddings call succeeds. The catalog names are openai/text-embedding-3-small, openai/text-embedding-3-large, and openai/text-embedding-ada-002, with the openai/ prefix. To send the bare OpenAI name (text-embedding-3-small) unchanged, the admin clicks Add OpenAI embedding aliases under AI Gateway → Providers → Aliases.

Environment variables ​

If you'd rather not hard-code values, the SDK reads OPENAI_BASE_URL and OPENAI_API_KEY automatically:

bash
export OPENAI_BASE_URL="https://your-corveil-host/v1"
export OPENAI_API_KEY="sk-citadel-your-key-here"

Troubleshooting ​

  • 404 / wrong path: Make sure base_url includes the /v1 suffix
  • 401 Unauthorized: Confirm the Corveil key has access to the requested model