Skip to main content

OpenAI Python SDK

Change one line — everything else works identically.

pip install openai

Before (direct to OpenAI)

from openai import OpenAI
client = OpenAI(api_key="sk-...")

After (through Autrace)

from openai import OpenAI
client = OpenAI(
base_url="https://gateway.autraceai.com/v1",
api_key="aut_live_YOUR_KEY",
)

Full example

from openai import OpenAI

client = OpenAI(
base_url="https://gateway.autraceai.com/v1",
api_key="aut_live_YOUR_KEY",
)

response = client.chat.completions.create(
model="openai/gpt-5.5",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Summarize this contract."},
],
)
print(response.choices[0].message.content)

Streaming

with client.chat.completions.stream(
model="openai/gpt-5.5",
messages=[{"role": "user", "content": "Write a poem."}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)

Streaming works transparently — the gateway captures the full exchange in the audit log.