Key takeaways
- The OpenAI SDK is the official client library, mainly for Python and JavaScript, that calls OpenAI's APIs.
- OpenAI-compatible APIs copy OpenAI's request format, so the same SDK can call other providers or local servers by changing the base URL.
- The OpenAI Cookbook on GitHub has hundreds of worked examples.
- LangChain is a framework for building chains and agents across providers; the SDK is a thin client for one provider.
- For transcription, compare OpenAI, Groq-hosted Whisper and Mistral's speech models on your own audio for accuracy, speed and cost.
The OpenAI SDK is OpenAI's official client library, mainly for Python and JavaScript or TypeScript, that wraps its APIs so you can generate text, use tools, create embeddings, process files, generate images and transcribe audio with a few lines of code. Because many providers and local servers copy OpenAI's API format, the same SDK often works with them too. This page covers the SDK and APIs, OpenAI-compatible APIs, Python and GitHub examples, processing PDFs, Sora, the SDK versus LangChain, using the OpenAI SDK with Anthropic, and transcription options from OpenAI, Groq and Mistral.
What is the OpenAI SDK?
The OpenAI SDK is the official library for calling OpenAI's APIs from code, handling authentication, requests, retries, streaming, typed responses and errors. The main SDKs are for Python and JavaScript or TypeScript, with official libraries for other languages as well.
Also asked as: what is openai sdk
Install it with pip install openai or npm install openai, set the OPENAI_API_KEY environment variable, and create a client. The SDK mirrors the API: methods for responses or chat completions, embeddings, files, images, audio, fine-tuning and batches. It retries transient errors automatically and supports async usage. Use the SDK rather than raw HTTP for real projects; it prevents many small mistakes.
What are the OpenAI APIs?
OpenAI's APIs give programmatic access to its models: text generation with tools and structured outputs, embeddings for search, image generation and editing, speech-to-text and text-to-speech, realtime voice, file handling, batch processing and fine-tuning.
Also asked as: what are openai apis
The core is text generation: you send input and instructions, and receive output, optionally with tool calls your code executes. Embeddings turn text into vectors for semantic search and RAG. Audio APIs transcribe and speak. The Batch API processes large jobs asynchronously at lower cost. All are billed per use, separately from ChatGPT subscriptions, and governed by OpenAI's data policies, under which API data is not used for training by default.
What are OpenAI-compatible APIs?
OpenAI-compatible APIs are services that accept the same request and response format as OpenAI's API, especially chat completions and embeddings, so you can use the OpenAI SDK with them by changing the base URL, API key and model name.
Also asked as: what are openai compatible apis
Examples include local servers such as Ollama, vLLM and LM Studio, and many hosted providers of open models. This makes switching providers easy:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama") # local Ollama
r = client.chat.completions.create(model="llama3.2", messages=[{"role": "user", "content": "Hi"}])
Compatibility usually covers common features, not every OpenAI capability, so test tool calling and structured outputs with each provider.
What are some OpenAI examples in Python?
The basic pattern is: create a client, call a generation method with a model and input, and read the output. Here is a minimal text generation and an embedding call.
Also asked as: openai examples python
from openai import OpenAI
client = OpenAI() # reads OPENAI_API_KEY
resp = client.responses.create(model="MODEL_NAME", input="Explain BM25 in two sentences.")
print(resp.output_text)
emb = client.embeddings.create(model="EMBEDDING_MODEL", input="hybrid search")
print(len(emb.data[0].embedding))
Replace the model names with current ones from the models page. From here, add streaming for chat interfaces, tools for actions, and structured outputs with a JSON schema for data extraction.
Where can I find OpenAI examples on GitHub?
The OpenAI Cookbook on GitHub has hundreds of notebooks and guides covering embeddings and search, RAG, function calling, agents, evaluation, fine-tuning, audio and more. The official SDK repositories also include example code.
Also asked as: openai examples github
Use the Cookbook to learn patterns, then adapt them to your project. Some notebooks use older model names or APIs, so check the date and the current documentation before copying. Many open-source projects on GitHub show complete applications built with the SDK, which are useful for seeing how pieces fit together in production, such as configuration, error handling and testing.
How can I process a PDF using OpenAI's APIs?
You can upload PDFs as file inputs to OpenAI's models, which read both text and page images, then ask questions or extract data. In ChatGPT and custom GPTs, you attach PDFs as files or knowledge. For large collections, extract text and build a RAG pipeline.
Also asked as: how can i process a pdf using openai's apis (gpts
Approaches by need:
- One document, questions or summary: send the PDF as a file input with your instructions.
- Structured extraction: request JSON matching a schema and validate the output.
- Many documents: extract text, chunk with page numbers, embed, and retrieve relevant passages for each question.
- Scanned PDFs: run OCR first or rely on the model's vision for small volumes.
DocuLens AI follows the extraction pattern: model output validated against a schema before anything is trusted.
Are there OpenAI examples for Sora?
Yes. OpenAI provides documentation and examples for Sora, its video generation model, both in the Sora app and, where available, through the API for developers. Examples show prompt structure and how to request and retrieve generated videos.
Also asked as: openai examples sora
Good Sora prompts describe the scene like a director: subject, action, setting, camera movement, lighting, style and duration. Generating video takes longer than text, so applications typically submit a job and check for completion. Availability, limits and pricing vary by plan and region, so check OpenAI's current documentation. Label AI-generated videos when publishing, and avoid generating real people without consent.
What is the difference between the OpenAI SDK and LangChain?
The OpenAI SDK is a thin, official client for OpenAI's APIs. LangChain is a framework for building LLM applications, with abstractions for prompts, chains, retrieval, tools, agents and memory across many providers, including OpenAI.
Also asked as: difference between openai sdk and langchain
Use the SDK when you want direct control, fewer dependencies and the newest features as soon as they are released. Use LangChain, or LangGraph for agents, when you want ready-made integrations for many vector stores, loaders and providers, or a structured way to build multi-step agents. Many production teams use the provider SDK directly with a small amount of their own code, because it is easier to debug; others use frameworks to move faster.
Why use the OpenAI SDK with the Anthropic API?
Anthropic provides an OpenAI SDK compatibility layer so developers can test Claude models with existing OpenAI-style code by changing the base URL, API key and model name. It is useful for quick comparisons and migrations.
Also asked as: why use openai sdk with anthropic api
For full access to Claude's features, such as extended thinking controls, prompt caching options and other Claude-specific capabilities, Anthropic recommends its own SDK. A practical path: evaluate Claude through the compatibility layer, then move to the Anthropic SDK if you adopt it. Design your code with a thin provider interface so switching or falling back between providers, as RAG.NextUpgrad does, is straightforward.
OpenAI vs Groq vs Mistral for transcription: which should I use?
All three offer speech-to-text APIs: OpenAI provides its transcription models, Groq hosts Whisper models on very fast inference hardware, and Mistral offers its own speech-understanding models. Choose by accuracy on your audio, speed, features, data terms and cost.
Also asked as: transcription apis – openai vs. groq vs. mistral
How to decide:
- Transcribe 20 of your real recordings with each and compute word error rate against corrected transcripts.
- Measure latency for your file sizes or streaming needs.
- Check language support, especially Indian languages and mixed speech.
- Compare features: timestamps, speaker labels, translation.
- Read data retention terms.
For privacy or zero per-minute cost, self-host open Whisper models instead; my OCR & Speech Workspace taught me that once speech becomes text, every other step gets easier.





