# OpenAI SDK
The OpenAI SDK is the official client library for [[OpenAI]]'s API platform. Officially maintained in **Python** (`openai`), **TypeScript / Node.js** (`openai`), **Go** (`openai-go`), **.NET** (`OpenAI`), and **Java** (`openai-java`). It is the *model SDK* layer ; a typed wrapper over OpenAI's HTTP API, not an agent runtime. For an OpenAI-hosted agent loop see [[OpenAI Agents SDK]] (a separate library).
Beyond OpenAI itself, the SDK has become a **de facto API standard**: many providers ([[Groq]], Together AI, Fireworks, Perplexity, Anyscale, Cerebras, Ollama's OpenAI-compatibility mode, [[Vercel AI Gateway]]) expose an OpenAI-shaped endpoint. Pointing the SDK at a different `base_url` Just Works for chat completions in most cases ; one of the reasons tooling has consolidated around it.
## API Surfaces
The SDK currently exposes two parallel "main" endpoints, plus everything else:
- **Responses API** (newer, agentic) ; built-in tool use, web search, file search, computer use, structured outputs, multi-turn state managed server-side
- **Chat Completions API** (classic) ; the original `/v1/chat/completions` shape every other provider mimics
- **Realtime API** ; voice + low-latency streaming for live agents
- **Assistants API** (legacy, being deprecated in favour of Responses)
- **Embeddings**, **Moderations**, **Files**, **Batch**, **Fine-tuning**
- **Images** (DALL-E / GPT image)
- **Audio** (Whisper transcription, TTS)
## Python Example
```python
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-5",
input="Explain the responses API in one paragraph.",
)
print(response.output_text)
```
## TypeScript Example
```ts
import OpenAI from "openai";
const client = new OpenAI();
const response = await client.responses.create({
model: "gpt-5",
input: "Explain the responses API in one paragraph.",
});
console.log(response.output_text);
```
## Provider Compatibility Pattern
```python
# Same SDK, different base_url → talk to Groq, Together, Fireworks, etc.
client = OpenAI(
base_url="https://api.groq.com/openai/v1",
api_key=os.environ["GROQ_API_KEY"],
)
```
This is why OpenAI's API shape became the lingua franca: the SDK abstraction wins by ubiquity even when the underlying model isn't from OpenAI.
## Where It Fits in the Stack
- **OpenAI models, full loop control** → OpenAI SDK directly
- **OpenAI loop + agent primitives (planning, tools, web search, computer use as managed)** → [[OpenAI Agents SDK]]
- **Provider neutrality** → [[Vercel AI SDK]] (TS) or [[LiteLLM]] (Python)
- **OpenAI-shaped API against another provider** → OpenAI SDK with custom `base_url`
## Notable Features
- **Streaming** ; SSE-based token streaming with helper hooks (`stream=True`, `for event in stream`)
- **Structured outputs** ; pass a Pydantic model ([[Pydantic]]) or Zod schema to constrain output to JSON matching the schema
- **Tool use** ; declare tools, get back tool-call requests, execute them, feed results back
- **Batch API** ; ~50% off for async workloads
- **Prompt caching** ; automatic on Responses API for stable prefix segments
- **Logprobs** ; token-level confidence and alternatives
## License
Apache-2.0. Source repos under https://github.com/openai/.
## References
- Python SDK: https://github.com/openai/openai-python
- TypeScript SDK: https://github.com/openai/openai-node
- API reference: https://platform.openai.com/docs/api-reference
## Related
- [[OpenAI]]
- [[OpenAI Agents SDK]]
- [[OpenAI Codex]]
- [[Anthropic SDK]]
- [[AI SDKs]]
- [[Vercel AI SDK]]
- [[LiteLLM]]
- [[Groq]]
- [[Pydantic]]