Build a chatbot that answers questions using GPT by calling the library's chat.completions.create method.
Add image understanding to your app by passing a photo URL to the vision endpoint and asking questions about it.
Stream text responses word-by-word in a web app using Server-Sent Events for a more interactive feel.
Handle thousands of concurrent API requests in a cloud environment using async/await syntax.
Requires a valid OpenAI API key to make actual API calls.
This is the official Python library that lets your code talk to OpenAI's models. It wraps OpenAI's REST API so that instead of building HTTP requests by hand, you import a client, pass your API key, and call methods like generating text from a model or asking it questions about an image. The README says the library works from any Python 3.9+ application and ships with type definitions for every request parameter and response field, which is what gives your editor autocompletion and type checks. Both synchronous and asynchronous clients are included; the async version is powered by httpx by default, with aiohttp available as an alternative HTTP backend for higher concurrency. The library is generated from OpenAI's published OpenAPI specification using Stainless. The primary path described in the README is the Responses API for text generation; the older Chat Completions API is also supported indefinitely. The README walks through installing with pip install openai, sending text prompts, sending image prompts as a URL or as base64, and streaming responses back using Server-Side Events. It also documents workload-identity authentication for Kubernetes, Azure managed identity, and Google Cloud Platform, so you can use short-lived cloud-issued tokens instead of long-lived API keys. Someone would reach for this any time they want a Python program, a script, web backend, or notebook, to call OpenAI's models. The full README is longer than what was provided.
Generated 2026-05-21 · Model: sonnet-4-6 · Verify against the repo before relying on details.