Chat

OpenAI Chat examples for multimodal input and output, tools, reasoning, structured output, storage, and retries.

ExampleDescription
Access Memories in Memory Completed EventStream an agent run with stream_events=True and read user memories off the MemoryUpdateCompleted event, backed by PostgresDb.
Chat Agent Flex TierRun o4-mini on the flex service tier by setting service_tier on OpenAIChat.
OpenAI Audio Input AgentSend a WAV file fetched from a URL to gpt-audio and stream a text answer about it.
OpenAI Audio Input And Output Multi TurnSend audio input and retain conversation history with the required database adaptation.
OpenAI Audio Input Local File UploadSend a local MP3 file to gpt-audio and get a text description of the audio.
OpenAI Audio Output AgentGet text and audio output from gpt-audio and save each spoken reply to a WAV file.
OpenAI Audio Output StreamStream pcm16 audio from gpt-audio, printing the transcript while writing frames to a WAV file.
Chat BasicRun a gpt-5.6-luna agent in sync, async, and streaming modes with OpenAIChat.
OpenAI Basic Stream MetricsStream a response, then read run-level and per-message metrics from the last run output.
OpenAI Chat CitationsCompare legacy chat annotations with a current Responses web-search example.
Custom Role MapPoint OpenAIChat at Mistral's base_url and remap the model role to assistant via role_map.
Chat DBStore session history in Postgres so a follow-up question can reference the previous answer.
OpenAI Generate ImagesLegacy DalleTools example that generates an image and reads its URL from the run output.
Chat Image AgentAnalyze an image from a URL and search the web for related news, streaming the reply.
Chat Image Agent BytesPass an image as raw bytes and combine vision with web search for current news.
Chat Image Agent FileAttach a local image by filepath, with auto-detected or explicit MIME types.
Chat Image Agent with MemoryAnalyze an image with web search and retain history with the required database adaptation.
Chat KnowledgeLoad a PDF into PgVector-backed knowledge and answer questions from its contents.
Chat MemoryStore user memories and session summaries in Postgres and print them after each turn.
OpenAI MetricsPrint per-message and aggregated run metrics after a YFinance tool call.
OpenAI PDF Input BytesAttach a PDF as raw bytes and ask for a summary.
PDF Input File UploadAttach a local PDF file to an OpenAI chat agent and ask it to suggest a recipe from the document.
Chat PDF Input LocalAttach a local PDF by filepath and query its contents with gpt-5.6-luna.
Chat PDF Input URLAttach a PDF by URL and ask the agent for a recipe from the file.
Chat Reasoning O3 MiniRun o3-mini with high reasoning effort and YFinance tools to write a stock report.
RetryReview retry settings and why invalid model IDs cannot reliably exercise the retry path.
Chat Structured OutputCompare JSON mode, strict, and guided structured output for a Pydantic movie schema.
Text-to-Speech AgentGenerate speech with the OpenAITools speech toolkit and save the returned audio to tmp/speech_output.mp3.
Chat Tool UseAnswer questions with web search tools in sync, streaming, and async modes.
Chat Verbosity ControlControl response length with the gpt-5 verbosity parameter in a finance report agent.
OpenAI With RetriesReview retry settings and why invalid model IDs cannot reliably exercise the retry path.