The client.chat.completions.create() method is the workhorse for text generation. You pass a model name, a messages array, and optional parameters.
Async Version
The messages array preserves conversation context. For multi-turn chats, append each assistant response and new user message to the array before the next call.
The shape that doesn't change
Every chat.completions.create call has three required arguments: model, messages, and (for Responses-class models) max_completion_tokens. Every response has id, choices, usage, and created. Knowing this skeleton from memory pays back fast — you stop reaching for docs for the obvious shape and only look up the unusual parameters.
The trap of conversational ergonomics
Because the API is stateless, building a chat UI on top is the developer's responsibility. The most common bug is to keep growing the message array forever — by week three, every request sends 20K tokens of history for a 50-token user message. The trim-by-tokens exercise below is the canonical fix.