Python SDK
Use the OpenAI Python SDK with Foza
Installation#
pip install openaiBasic Usage#
from openai import OpenAI client = OpenAI( base_url="https://api.foza.ai/v1", api_key="sk-foza-xxxxx", ) response = client.chat.completions.create( model="openai/gpt-4o", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is the capital of France?"}, ], ) print(response.choices[0].message.content)
Streaming#
stream = client.chat.completions.create( model="anthropic/claude-sonnet-4.6", messages=[{"role": "user", "content": "Tell me a story"}], stream=True, ) for chunk in stream: content = chunk.choices[0].delta.content if content: print(content, end="", flush=True)
Async Usage#
import asyncio from openai import AsyncOpenAI client = AsyncOpenAI( base_url="https://api.foza.ai/v1", api_key="sk-foza-xxxxx", ) async def main(): response = await client.chat.completions.create( model="openai/gpt-4o", messages=[{"role": "user", "content": "Hello!"}], ) print(response.choices[0].message.content) asyncio.run(main())
The Foza API is fully compatible with the OpenAI Python SDK. Any code using openai just needs the base_url changed.