Skip to content
Dashboard

OpenAI-compatible API endpoints now supported in AI Gateway

from openai import OpenAI
client = OpenAI(
api_key='my-ai-gateway-key',
base_url='https://ai-gateway.vercel.sh/v1'
)
stream = client.chat.completions.create(
model='anthropic/claude-4-sonnet',
messages=[
{
'role': 'user',
'content': 'Write a one-sentence bedtime story about a unicorn.'
}
],
stream=True,
)
for chunk in stream:
content = chunk.choices[0].delta.content if chunk.choices[0].delta.content else None
if content:
print(content, end='', flush=True)
print()