Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions examples/samples/openai_responses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""OpenAI Responses API — stream text from GPT-5.5."""

import asyncio
import sys

import ai

if ai.openai.client().api_key is None:
print(f"[SKIP] {ai.openai.api_key_env} not set")
sys.exit(0)

model = ai.openai("gpt-5.5")

messages = [
ai.system_message("Be concise."),
ai.user_message("Explain what the OpenAI Responses API is in two sentences."),
]


async def main() -> None:
async with ai.stream(model, messages) as stream:
async for event in stream:
if isinstance(event, ai.events.TextDelta):
print(event.chunk, end="", flush=True)
print()


if __name__ == "__main__":
asyncio.run(main())
2 changes: 2 additions & 0 deletions src/ai/models/core/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ def _ensure_adapters() -> None:
from ..ai_gateway.adapter import stream as ai_gw_stream
from ..anthropic.adapter import stream as anthropic_stream
from ..openai.adapter import stream as openai_stream
from ..openai.chat_adapter import stream as openai_chat_stream

_stream_adapters["ai-gateway-v3"] = ai_gw_stream
_generate_adapters["ai-gateway-v3"] = ai_gw_generate
_stream_adapters["openai"] = openai_stream
_stream_adapters["openai.chat"] = openai_chat_stream
_stream_adapters["anthropic"] = anthropic_stream


Expand Down
3 changes: 2 additions & 1 deletion src/ai/models/openai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

from ai.models import openai

model = openai("gpt-5.4")
model = openai("gpt-5.4") # Responses API
chat_model = openai.chat("gpt-4o") # Chat Completions API
ids = await openai.list()

The adapter module is loaded lazily to avoid pulling in the ``openai``
Expand Down
Loading
Loading