> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat

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

| Example                                                                                                             | Description                                                                                                                    |
| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| [Access Memories in Memory Completed Event](/examples/models/openai/chat/access-memories-in-memory-completed-event) | Stream an agent run with stream\_events=True and read user memories off the MemoryUpdateCompleted event, backed by PostgresDb. |
| [Chat Agent Flex Tier](/examples/models/openai/chat/agent-flex-tier)                                                | Run o4-mini on the flex service tier by setting service\_tier on OpenAIChat.                                                   |
| [OpenAI Audio Input Agent](/examples/models/openai/chat/audio-input-agent)                                          | Send a WAV file fetched from a URL to gpt-audio and stream a text answer about it.                                             |
| [OpenAI Audio Input And Output Multi Turn](/examples/models/openai/chat/audio-input-and-output-multi-turn)          | Send audio input to gpt-audio and carry the conversation across turns with audio replies.                                      |
| [OpenAI Audio Input Local File Upload](/examples/models/openai/chat/audio-input-local-file-upload)                  | Upload a local MP3 file to gpt-audio and get a text description of the audio.                                                  |
| [OpenAI Audio Output Agent](/examples/models/openai/chat/audio-output-agent)                                        | Get text and audio output from gpt-audio and save each spoken reply to a WAV file.                                             |
| [OpenAI Audio Output Stream](/examples/models/openai/chat/audio-output-stream)                                      | Stream pcm16 audio from gpt-audio, printing the transcript while writing frames to a WAV file.                                 |
| [Chat Basic](/examples/models/openai/chat/basic)                                                                    | Run a gpt-4o agent in sync, async, and streaming modes with OpenAIChat.                                                        |
| [OpenAI Basic Stream Metrics](/examples/models/openai/chat/basic-stream-metrics)                                    | Stream a response, then read run-level and per-message metrics from the last run output.                                       |
| [Custom Role Map](/examples/models/openai/chat/custom-role-map)                                                     | Point OpenAIChat at Mistral's base\_url and remap the `model` role to `assistant` via role\_map.                               |
| [Chat DB](/examples/models/openai/chat/db)                                                                          | Store session history in Postgres so a follow-up question can reference the previous answer.                                   |
| [OpenAI Generate Images](/examples/models/openai/chat/generate-images)                                              | Legacy DalleTools example that generates an image and reads its URL from the run output.                                       |
| [Chat Image Agent](/examples/models/openai/chat/image-agent)                                                        | Analyze an image from a URL and search the web for related news, streaming the reply.                                          |
| [Chat Image Agent Bytes](/examples/models/openai/chat/image-agent-bytes)                                            | Pass an image as raw bytes and combine vision with web search for current news.                                                |
| [Chat Image Agent with Memory](/examples/models/openai/chat/image-agent-with-memory)                                | Analyze an image with web search, keeping chat history so follow-ups can reference it.                                         |
| [Chat Knowledge](/examples/models/openai/chat/knowledge)                                                            | Load a PDF into PgVector-backed knowledge and answer questions from its contents.                                              |
| [Chat Memory](/examples/models/openai/chat/memory)                                                                  | Store user memories and session summaries in Postgres and print them after each turn.                                          |
| [OpenAI Metrics](/examples/models/openai/chat/metrics)                                                              | Print per-message and aggregated run metrics after a YFinance tool call.                                                       |
| [PDF Input File Upload](/examples/models/openai/chat/pdf-input-file-upload)                                         | Attach a local PDF file to an OpenAI chat agent and ask it to suggest a recipe from the document.                              |
| [Chat PDF Input Local](/examples/models/openai/chat/pdf-input-local)                                                | Attach a local PDF by filepath and query its contents with gpt-4o.                                                             |
| [Chat PDF Input URL](/examples/models/openai/chat/pdf-input-url)                                                    | Attach a PDF by URL and ask the agent for a recipe from the file.                                                              |
| [Chat Reasoning O3 Mini](/examples/models/openai/chat/reasoning-o3-mini)                                            | Run o3-mini with high reasoning effort and YFinance tools to write a stock report.                                             |
| [Retry](/examples/models/openai/chat/retry)                                                                         | Review retry settings and why invalid model IDs cannot reliably exercise the retry path.                                       |
| [Chat Structured Output](/examples/models/openai/chat/structured-output)                                            | Compare JSON mode, strict, and guided structured output for a Pydantic movie schema.                                           |
| [Text-to-Speech Agent](/examples/models/openai/chat/text-to-speech-agent)                                           | Generate speech with the OpenAITools speech toolkit and save the returned audio to tmp/speech\_output.mp3.                     |
| [Chat Tool Use](/examples/models/openai/chat/tool-use)                                                              | Answer questions with web search tools in sync, streaming, and async modes.                                                    |
| [Chat Verbosity Control](/examples/models/openai/chat/verbosity-control)                                            | Control response length with the gpt-5 verbosity parameter in a finance report agent.                                          |
| [OpenAI With Retries](/examples/models/openai/chat/with-retries)                                                    | Review retry settings and why invalid model IDs cannot reliably exercise the retry path.                                       |
