ModelRefs / OpenAI Python SDK — AI Glossary

OpenAI Python SDK — AI Glossary

The official Python client library for the OpenAI API, providing typed request/response models, async support, and streaming helpers.

Overview

openai-python (v1.x, fully typed, httpx-based) provides: ChatCompletion.create (sync/async), streaming helpers (stream() context manager), tool call parsing, automatic retries with exponential backoff, and response validation. Used directly and as a dependency by LangChain, LlamaIndex, and most Python LLM tooling.

Reference details

Topicecosystem
Also known asopenai Python library
Last reviewed2026-06-24

How it works

  1. A typed client wraps the HTTP API, so request and response shapes are checked at the call site rather than discovered at runtime.
  2. Streaming is exposed as a context manager yielding typed events, which is what lets partial tool-call arguments be assembled as they arrive.
  3. Retries with exponential backoff are built in for transient failures, so a 429 or 5xx is retried without application code.
  4. Tool calls return structured objects the caller executes and returns as tool-role messages, making the loop explicit in application code.
  5. Because the request shape became a de facto convention, other providers expose compatible endpoints — so the same client often works against them with a changed base URL.

Example: What built-in backoff actually costs you

Default retries with exponential backoff might wait 1s, then 2s, then 4s. A request that fails three times before succeeding therefore takes about 7 seconds of waiting plus four round trips, and from the caller's perspective it is one slow call rather than four failures. That is usually right — and it means a client-side timeout shorter than the backoff ladder will cancel a request the SDK would have completed, which is the misconfiguration that makes an otherwise healthy integration look flaky.

Commonly confused with

The official client for one provider, not a multi-provider abstraction — that is LiteLLM or a gateway. Worth separating from the OpenAI-compatible *interface*: many providers accept the same request shape, so this client can often be pointed at them by changing the base URL, but doing so gives you the shape and not the behaviour, since parameter support and error semantics vary.

When to use it

Reach for it when:

  • Calling that provider directly from Python with streaming, tool use or structured output.
  • Targeting an OpenAI-compatible endpoint, where the same client works with a different base URL.
  • Typed request and response handling is wanted over raw HTTP.

Reach for something else when:

  • You need genuine multi-provider abstraction with fallbacks — that is a gateway's job.
  • Assuming compatibility is total: compatible endpoints often omit newer parameters.
  • Client timeouts are set below the retry ladder, which cancels work the SDK would finish.

Continue your research

Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to OpenAI Python SDK — AI Glossary.

Frequently asked questions

What is OpenAI Python SDK?

The official Python client library for the OpenAI API, providing typed request/response models, async support, and streaming helpers.

Is OpenAI Python SDK the same as openai Python library?

Yes — openai Python library are common aliases for OpenAI Python SDK.

What concepts are related to OpenAI Python SDK?

Closely related concepts include anthropic sdk, sdk, openai api.