SDKs and CLI
发布时间:2026-09-22 | 浏览:1
Search the API docs
Using GPT-6 Astra
Conversation state
Background mode
Mid-turn steering
Counting tokens
Supported countries
OpenAI Crawlers
Terms and policies
Agent Builder Overview Migration guide Node reference Safety in building agents
Migration guide
Safety in building agents
Evals Getting started Working with evals Prompt optimizer External models Best practices Graders
Getting started
Working with evals
Prompt optimizer
External models
Fine-tuning Optimization cycle Supervised fine-tuning Vision fine-tuning Direct preference optimization Reinforcement fine-tuning RFT use cases Best practices
Optimization cycle
Supervised fine-tuning
Vision fine-tuning
Direct preference optimization
Reinforcement fine-tuning
Assistants API Migration guide
Migration guide
Model selection
Text generation
Code generation
Structured output
Prompt engineering
Citation formatting
Migration guide
Prompt generation
Frontend prompting
Reasoning models
Reasoning best practices
Images and video
Images and vision Image input cost calculator
Image input cost calculator
Image generation Overview Image prompting
Image prompting
Video generation
Realtime and audio
Audio and speech
Getting started
Specialized models
Configuring Agents
Sessions Run and continue sessions Events and items Manage sessions Webhooks
Run and continue sessions
Events and items
Manage sessions
Environments and sandboxes OpenAI-hosted sandboxes Self-hosted sandboxes Sandbox lifecycle Sandbox security Files and artifacts
OpenAI-hosted sandboxes
Self-hosted sandboxes
Sandbox lifecycle
Sandbox security
Files and artifacts
Tools and integrations Web search Functions MCP connections Plugins Vaults
MCP connections
Observability and usage
Agent definitions
Models and providers
Results and state
Integrations and observability
Evaluate agent workflows
Advanced integrations
Function calling
Search and retrieval
Connect tools and data
Secure MCP Tunnel
Build tool workflows
Programmatic tool calling
Async tool calling
Computer and code
Code interpreter
Image generation
Getting started
Managing sessions
Delegation and tools
Migrate to GPT-Live
Partner integrations
Getting started
Managing conversations
Voice activity detection
Build with voice
Cost optimization
WebRTC with WARP
Telephony and SIP
Server-side controls
Audio processing
File transcription
Live transcription
Live translation
Audio in Chat Completions
Production best practices
Deployment checklist
Performance and quality
Latency optimization
Predicted Outputs
Accuracy optimization
Cost and throughput
Cost optimization
Prompt caching Prompt cache diagnostics
Prompt cache diagnostics
Flex processing
Safety and governance
Safety best practices
Safety checks Safety classifiers Cybersecurity checks Misalignment monitoring
Safety classifiers
Cybersecurity checks
Misalignment monitoring
Under-18 guidance
Content provenance
Infrastructure and access
Terraform provider Overview Projects and access Service accounts Rate limits and spend Model, tool, and data controls Import and reconciliation
Projects and access
Service accounts
Rate limits and spend
Model, tool, and data controls
Import and reconciliation
Workload identity federation Federation rules X.509 certificates Kubernetes AWS Microsoft Azure Google Cloud Oracle Cloud Infrastructure GitHub Actions SPIFFE
Federation rules
X.509 certificates
Microsoft Azure
Oracle Cloud Infrastructure
IP egress ranges
Plugin architecture
Brainstorm use cases
Build an MCP server
Add UI to your MCP server (optional)
Authenticate users
Package your plugin
Test and publish
Connect and test your plugin
Submit and publish
Submission error reference
Conversion specs
Restaurant reservation spec
Product checkout spec
Optimize Metadata
Submit a Claude Code plugin
Security & Privacy
Troubleshooting
Plugin guidelines
MCP server review requirements
Plugin UI reference
Checkout API reference
Trigger workspace agent runs
Authenticate with Workspace Agent access tokens
Measurement Pixel
Multiple Pixels (Advanced)
Conversions API
Supported Events
Campaign Management
Bidding & Budgets
Conversion Tracking
Troubleshooting
Account Management
Conversion Setup
Get started with Work
Import from another agent
Personalize ChatGPT
Skills & Plugins
ChatGPT desktop app
ChatGPT on the web
Codex IDE extension
Feature Maturity
Projects and chats
Scheduled tasks
Long-running work
Image generation
Browser extension
Work with files
Troubleshooting
Computer History
Advanced Config
Config Reference
Environment Variables
Agent configuration
Extend ChatGPT and Codex
Record & Replay
Windows sandbox
Development workflows
Integrated terminal
Extend and automate
Site tools (WebMCP)
Local environments
Cloud environment
Build with Codex
Non-interactive mode
Third-party integrations
CLI customization
Developer commands
Developer settings
Agent approvals & security
Internet access
Codex Security plugin Quickstart Run a security scan Run a deep scan Review code changes Use the Security workbench Triage a backlog Fix findings Propose security hardening Write vulnerability reports Export and track findings Changelog
Run a security scan
Run a deep scan
Review code changes
Use the Security workbench
Triage a backlog
Propose security hardening
Write vulnerability reports
Export and track findings
Codex Security CLI Quickstart Run bulk scans Run scans in CI GitLab CI/CD Reference FAQ
Run scans in CI
Codex Security cloud Setup Security Review Improving the threat model FAQ
Security Review
Improving the threat model
Models & Trusted Access
Recommended configuration
Getting started
Admin rollout guide
ChatGPT Work Overview
ChatGPT Work cloud security
ChatGPT Work local security
ChatGPT Work admin FAQ
ChatGPT Work: usage and cost
Identity and authentication
Authentication overview
Personal Access Tokens
Service accounts
Workspace access, policy, and models
Groups and provisioning
User lifecycle management
Roles and workspace permissions
GPTs and Sharing
Managed configuration
HIPAA configuration
Workspace model availability
Plugin and connector controls
Plugin controls
Plugin management
Usage, governance, and compliance
Workspace analytics
Compliance API and audit events
Deployment and model providers
Manage app updates
Windows app deployment
Remote connections
Explore use cases
Online trainings
Codex Ambassadors
Codex for Students
Codex for Open Source
Explore use cases
Online trainings
Codex Ambassadors
Codex for Students
Codex for Open Source
Rethinking skills and prompts for GPT-6 Astra
Architectural visualization with Astra
Building games with Astra
Meet Rosalind Workbench: Empowering every scientist to be their own research team
Automating repetitive work at OpenAI with Codex
Cookbook on GitHub
OpenAI Developers plugin
Image generation
Video generation
Codex Ambassadors
Codex for Students
Codex for Open Source
OpenAI for Startups
Developer Forum
This page covers the main ways to build with the OpenAI API : official SDKs for application code, the OpenAI CLI for shell-native workflows, the Agents SDK for orchestration, or your own preferred HTTP client.
Create and export an API key
Before you begin, create an API key in the dashboard , which you’ll use to securely access the API . Store the key in a safe location, like a .zshrc file or another text file on your computer. Once you’ve generated an API key, export it as an environment variable in your terminal.
OpenAI SDKs are configured to automatically read your API key from the system environment.
Install an official SDK
To use the OpenAI API in server-side JavaScript environments like Node.js, Deno, or Bun, you can use the official OpenAI SDK for TypeScript and JavaScript . Get started by installing the SDK using npm or your preferred package manager:
With the OpenAI SDK installed, create a file called example.mjs and copy the example code into it:
Execute the code with node example.mjs (or the equivalent command for Deno or Bun). In a few moments, you should see the output of your API request.
Discover more SDK capabilities and options on the library’s GitHub README.
To use the OpenAI API in Python, you can use the official OpenAI SDK for Python . Get started by installing the SDK using pip :
With the OpenAI SDK installed, create a file called example.py and copy the example code into it:
Execute the code with python example.py . In a few moments, you should see the output of your API request.
Discover more SDK capabilities and options on the library’s GitHub README.
In collaboration with Microsoft, OpenAI provides an officially supported API client for C#. You can install it with the .NET CLI from NuGet .
A simple API request to the Responses API would look like this:
OpenAI provides an API helper for the Java programming language, currently in beta. You can include the Maven dependency using the following configuration:
A simple API request to Responses API would look like this:
To learn more about using the OpenAI API in Java, check out the GitHub repo linked below!
Discover more SDK capabilities and options on the library’s GitHub README.
OpenAI provides an API helper for the Go programming language, currently in beta. You can import the library using the code below:
A first API request to the Responses API would look like this:
To learn more about using the OpenAI API in Go, check out the GitHub repo linked below!
Discover more SDK capabilities and options on the library’s GitHub README.
To use the OpenAI API in Ruby, you can use the official OpenAI SDK for Ruby . Get started by adding the gem to your application:
With the OpenAI SDK installed, create a file called example.rb and copy the example code into it:
Execute the code with ruby example.rb . In a few moments, you should see the output of your API request.
Discover more SDK capabilities and options on the library’s GitHub README.
To call the OpenAI API directly from your terminal, install the generated openai command-line tool:
Then run a basic API request from your shell:
Use the CLI for repeatable terminal workflows such as extracting structured data from files, generating images, creating speech, and composing API calls with shell tools like jq .
Learn more about CLI workflows and command patterns.
Use the Agents SDK
Use the official OpenAI SDKs above for direct API requests. Use the Agents SDK when your application needs code-first orchestration for agents, tools, handoffs, guardrails, tracing, or sandbox execution.
If you are deciding between direct API requests and code-first orchestration, see how the Responses API compares with the Agents SDK .
Build your first agent with the Agents SDK.
OpenAI Agents SDK for TypeScript
OpenAI Agents SDK for Python
Azure OpenAI libraries
Microsoft’s Azure team maintains libraries that are compatible with both the OpenAI API and Azure OpenAI services. Read the library documentation below to learn how you can use them with the OpenAI API.
Azure OpenAI client library for .NET
Azure OpenAI client library for JavaScript
Azure OpenAI client library for Java
Azure OpenAI client library for Go
Community libraries
The libraries below are built and maintained by the broader developer community. You can also watch our OpenAPI specification repository on GitHub to get timely updates on when we make changes to our API.
Please note that OpenAI does not verify the correctness or security of these projects. Use them at your own risk!
openai-clojure by wkok
openai by anasfik
DelphiOpenAI by HemulGM
openai.ex by mgallo
openai-kotlin by Mouaad Aallam
orhanerday/open-ai by orhanerday
openai-php client by openai-php
async-openai by 64bit
openai-scala-client by cequence-io
AIProxySwift by Lou Zell
OpenAIKit by dylanshine
OpenAI by MacPaw
com.openai.unity by RageAgainstThePixel
OpenAI-Api-Unreal by KellanM
Other OpenAI repositories
tiktoken - counting tokens
simple-evals - simple evaluation library
mle-bench - library to evaluate machine learning engineer agents
gym - reinforcement learning library
swarm - educational orchestration repository
Loading docs agent...