The OpenAI API provides a simple interface to state-of-the-art AI models for text generation, natural language processing, computer vision, and more. Get started by creating an API Key and running your first API call. Discover how to generate text, analyze images, build agents, and more.
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 the OpenAI SDK and Run an API Call
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.
dotnet add package OpenAI
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:
<dependency>
<groupId>com.openai</groupId>
<artifactId>openai-java</artifactId>
<version>4.0.0</version>
</dependency>
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:
import (
"github.com/openai/openai-go" // imported as openai
)
A simple 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.
Start building with the Responses API.
Learn more about prompting, message roles, and building conversational apps.
Add credits to keep building
Explore tools and docs designed to help you ship faster:
Build & test conversational prompts and embed them in your app.
Use the Agents SDK to build, run, and observe agent workflows.
Analyze images and files
Send image URLs, uploaded files, or PDF documents directly to the model to extract text, classify content, or detect visual elements.
Learn to use image inputs to the model and extract meaning from images.
Learn to use file inputs to the model and extract meaning from documents.
Extend the model with tools
Give the model access to external data and functions by attaching tools. Use built-in tools like web search or file search, or define your own for calling APIs, running code, or integrating with third-party systems.
Learn about powerful built-in tools like web search and file search.
Learn to enable the model to call your own custom code.
Stream responses and build realtime apps
Use server‑sent streaming events to show results as they’re generated, or the Realtime API for interactive voice and multimodal apps.
Use server-sent events to stream model responses to users fast.
Use WebRTC or WebSockets for super fast speech-to-speech AI apps.
Build agents
Use the OpenAI platform to build agents capable of taking action—like controlling computers—on behalf of your users. Use the Agents SDK to create orchestration logic on the backend.
Learn how to use the OpenAI platform to build powerful, capable AI agents.
