OpenAI API
The OpenAI API is the paid developer interface to OpenAI's models: programs send HTTPS requests to api.openai.com and receive generated text, structured data, images, audio or embeddings. Requests are authenticated with a secret API key, billing is per token, and the recommended endpoint for new projects is the Responses API. As of December 2026 the newest models are GPT-6.2 Astra and GPT-6.2 Sol.
Key facts
| Type | REST API for AI models: text, structured output, images, audio, embeddings |
| Owner | OpenAI |
| Base URL | https://api.openai.com/v1 |
| Format | JSON requests and responses; streaming via server-sent events |
| Authentication | Secret API key, sent as a Bearer token |
| Main endpoint | Responses API (POST /v1/responses) |
| Newest models | GPT-6.2 Astra and GPT-6.2 Sol (released November 17, 2026) |
| Pricing | Pay as you go, per million input and output tokens |
| Official libraries | Python, JavaScript/TypeScript, .NET, Java, Go |
| Documentation | developers.openai.com/api |
What is the OpenAI API?
The OpenAI API is a REST API through which programs use OpenAI's large language models and other models: an application sends a request with a prompt to api.openai.com and gets the model's answer back as JSON. It is a separate product from ChatGPT: a ChatGPT subscription does not include API usage, and the API is billed separately by the token.
Developers use the API to build chatbots and support assistants, summarise and classify documents, extract data into JSON, translate text, search by meaning with embeddings, transcribe speech and generate images.
Which parts does the OpenAI API have?
- Responses API (
/v1/responses) — the main endpoint for text and multimodal requests. It supports function calling, structured outputs with a JSON schema, built-in tools such as web search, file search and code interpreter, and multi-turn conversations throughprevious_response_id. - Chat Completions (
/v1/chat/completions) — the older message-based endpoint. It still works and is widely supported by third-party libraries. - Realtime API — low-latency speech-to-speech and voice agents over WebSocket or WebRTC.
- Embeddings — turn text into vectors for semantic search and recommendations.
- Images and audio — image generation and editing, speech-to-text and text-to-speech.
- Batch API — asynchronous processing of large request files at a lower price.
The Assistants API was shut down on August 26, 2026; OpenAI recommends the Responses API for agents and tools instead.
How do you get an OpenAI API key?
You get an API key in the OpenAI developer platform after creating an account and adding a payment method:
- Sign up at the developer platform and create an organisation and a project.
- Add a card in the billing settings and buy prepaid credits.
- Open the API keys page and create a key for the project. The key is shown only once.
- Store it in an environment variable such as
OPENAI_API_KEY, never in client-side code or a public repository.
Keys belong to projects, so one project's usage, limits and access can be managed separately from another's. A key that has leaked should be revoked immediately, because anyone holding it can spend the account's money.
How do you make a request to the OpenAI API?
A request is an HTTPS POST with the key in the Authorization header and the model and input in a JSON body:
curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-6.2-sol",
"input": "Explain what an API is in one sentence."
}'
The same request with the official Node.js library (npm install openai), which reads the key from OPENAI_API_KEY:
import OpenAI from 'openai';
const client = new OpenAI();
const response = await client.responses.create({
model: 'gpt-6.2-sol',
instructions: 'Answer briefly.',
input: 'What is the capital of Kazakhstan?',
});
console.log(response.output_text);
And in Python (pip install openai):
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-6.2-sol",
input="Write a short product description for a coffee shop app.",
)
print(response.output_text)
The response object contains the generated output, the model name and a usage block with the number of input and output tokens used, which is what the request is billed for. Adding "stream": true returns the answer in parts as it is generated.
Which models are available in the OpenAI API?
The current models belong to the GPT-6 family, which comes in three classes: Luna, the most efficient; Sol, for everyday tasks; and Astra, the most capable frontier model. GPT-6.2 Astra and GPT-6.2 Sol were released on November 17, 2026 and are available in the API as gpt-6.2-astra and gpt-6.2-sol. Older models remain available for some time after a new release, and OpenAI announces their retirement dates in advance.
How much does the OpenAI API cost?
The OpenAI API is billed per token, separately for input and output; prices per million tokens as published by OpenAI in November 2026:
| Model | Input | Cached input | Output |
|---|---|---|---|
GPT-6.2 Astra (gpt-6.2-astra) |
$8.00 | $0.40 | $40.00 |
GPT-6.2 Sol (gpt-6.2-sol) |
$2.00 | $0.10 | $10.00 |
A token is a piece of a word: in English one token is about four characters, while Russian and Kazakh text usually needs more tokens for the same number of words. For example, a request to GPT-6.2 Sol with 2,000 input tokens and a 500-token answer costs 2,000 × $2 / 1,000,000 + 500 × $10 / 1,000,000 = $0.009. Repeated parts of prompts are billed at the cached input price, and the Batch API is cheaper than synchronous requests. Current prices are listed on openai.com/api/pricing.
What are the OpenAI API rate limits?
Rate limits restrict how many requests (RPM) and tokens (TPM) a project can use per minute for each model. Limits depend on the usage tier: a new account starts low, and it moves to higher tiers automatically as it spends more and pays on time. When a limit is exceeded, the API returns HTTP 429, and the client should retry after a pause with exponential backoff. A 429 can also mean that prepaid credits have run out.
Can you use the OpenAI API from Kazakhstan?
Yes. Kazakhstan is on OpenAI's list of supported countries and territories for the API. Prices are in US dollars, so for a Kazakhstani company the cost in tenge changes with the exchange rate. Requests are processed on OpenAI's servers outside Kazakhstan, so a service that sends customers' personal data to the API should check the requirements of Kazakhstan's personal data law and describe the transfer in its privacy policy.
By default, OpenAI does not use data sent through the API to train its models.
Limitations
- Models can produce confident but wrong answers (hallucinations), so facts, code and calculations should be checked before use.
- Costs grow with traffic and prompt length; set a monthly budget and usage alerts in the project settings.
- New models and endpoints appear often, and old ones are retired: the Assistants API was shut down in 2026, so code needs regular updates.
- The secret key must stay on the server. Calling the API directly from a browser or mobile app exposes it.
Sources
- Introducing GPT-6.2 Astra and Sol — OpenAI (accessed 1 December 2026)
- Create a model response — OpenAI API Reference (accessed 1 December 2026)
- Assistants API (sunset) — OpenAI Developers (accessed 1 December 2026)
- OpenAI API supported countries and territories — OpenAI Help Center (accessed 1 December 2026)
- API Pricing — OpenAI (accessed 1 December 2026)