Read the latest
Guides/OpenAI SDK
OpenAI SDK guide
The OpenAI Python SDK end to end: Responses vs Chat, streaming, structured outputs, tools, embeddings, retries, cost and evals.
- 01How the OpenAI API worksUnder every chatbot, agent and 'AI feature' is the same exchange: your code sends an HTTP request containing a model name and some input, and gets back output plus…
- 02Setup, keys & your first callSetup takes five minutes: a virtual environment, the openai package, and an API key in an environment variable .
- 03Responses API vs Chat CompletionsOpenAI has two APIs for generating text. Chat Completions ( client.chat.completions.create ) is the older, widely copied format: a list of messages in, one message…
- 04Models, parameters & tokensWhich model you call decides quality, speed and cost more than any prompt trick.
- 05Streaming responsesA model generates output one token at a time. Without streaming you wait for the whole answer, perhaps 8 seconds for a long reply, and see nothing meanwhile.
- 06Structured outputs with PydanticMost application code does not want prose. It wants data : a category, an extracted invoice, a list of action items.
- 07Function calling: the tool loopA model cannot query your database or call your API. What it can do is ask you to . You describe functions (name, purpose, JSON Schema for the arguments).
- 08Built-in toolsFunction tools (part 07) run in your code. Built-in (hosted) tools run on OpenAI's side within the same request: web search , file search over your uploaded…
- 09Images, files & audioCurrent models read images and PDFs as naturally as text: a receipt photo, a chart screenshot, a 40-page contract.
- 10Embeddings & semantic searchAn embedding is a list of numbers (a vector) that represents the meaning of a piece of text.
- 11Async client & concurrencyEach API call spends almost all its time waiting for the model. Classifying 1,000 support tickets one at a time at 1.5 s each takes 25 minutes, and your CPU is idle…
- 12Errors, retries & timeoutsNetwork calls fail. Rate limits are hit, servers have bad minutes, requests are malformed, keys expire.
- 13Cost & latency optimisationLLM costs scale with tokens × price × requests, and latency scales mostly with output length and model size.
- 14Files, vector stores & managed retrievalTo answer questions from your own documents (policies, manuals, contracts), the model needs the relevant passages in its input.
- 15Conversation state & memoryThe model is stateless (part 01), so a chat must supply earlier turns on every call.
- 16Safety, moderation & data handlingAn LLM feature has a new kind of attack surface: text . Users can type instructions, documents and web pages can contain hidden instructions, and the model's output…
- 17The OpenAI Agents SDKIn part 07 you wrote the tool loop by hand. The Agents SDK ( pip install openai-agents ) packages that loop with a few primitives: an Agent (instructions + tools…
- 18Testing & evaluating LLM codeLLM features need two different kinds of checking. Tests check your code : does the tool loop pass the right call_id back, handle a 429, parse the schema, refuse an…
- 19Realtime & voiceA voice assistant built from three calls (transcribe → think → speak, part 09) works, but each hop adds latency, and conversation feels stilted.
- 20Project: retail analyst assistantAsk 'which category earned the most from completed orders?' in plain English and get a correct answer, with the numbers, the SQL that produced them, and caveats…