Repository Public
1# API Overview23> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.45Use this reference to look up OpenAI API endpoints, request and response6schemas, streaming events, client library methods, and shared behavior such as7authentication, errors, rate limits, and request IDs.89## Start here10111. Choose the API surface for your application:12 - [Responses](https://developers.openai.com/api/reference/responses/overview) for direct model requests, tool use, audio, image, and text inputs, and stateful interactions.13 - [Realtime API](https://developers.openai.com/api/docs/guides/realtime) for low-latency voice or audio sessions over WebRTC, WebSocket, or SIP. Use the [client events](https://developers.openai.com/api/reference/resources/realtime/client-events) and [server events](https://developers.openai.com/api/reference/resources/realtime/server-events) references while building sessions.14 - [Administration](https://developers.openai.com/api/reference/administration/overview) for organization workflows such as users, invites, projects, API keys, and audit logs.152. Create credentials. Use a standard [API key](https://platform.openai.com/settings/organization/api-keys) for application requests, an [Admin API key](https://platform.openai.com/settings/organization/admin-keys) for Administration endpoints, or [workload identity federation](https://developers.openai.com/api/docs/guides/workload-identity-federation) for short-lived access tokens.163. Install an official client library from the [libraries page](https://developers.openai.com/api/docs/libraries), or call the HTTP API directly from any environment that supports HTTP requests.174. Make a first request with the [developer quickstart](https://developers.openai.com/api/docs/quickstart) or go straight to the [Responses create reference](https://developers.openai.com/api/reference/resources/responses/methods/create).185. Before production, review [error codes](https://developers.openai.com/api/docs/guides/error-codes), [rate limits](https://developers.openai.com/api/docs/guides/rate-limits), and request ID logging below.1920## Authentication2122The OpenAI API accepts bearer credentials from API keys or from short-lived access tokens created with [workload identity federation](https://developers.openai.com/api/docs/guides/workload-identity-federation).2324**Remember that your API key is a secret.** Don't share it with others or expose it in any client-side code such as browsers or apps. Load API keys from an environment variable or key management service on the server.2526Revocations of an API key take effect within a few seconds. Most updates that27 affect authentication results of an API key propagate within 15 minutes, but28 can potentially take longer.2930Provide API credentials with [HTTP Bearer authentication](https://swagger.io/docs/specification/v3_0/authentication/bearer-authentication/).3132```bash33Authorization: Bearer OPENAI_API_KEY_OR_ACCESS_TOKEN34```3536If you belong to more than one organization or access projects through a legacy user API key, pass a header to specify which organization and project to use for an API request:3738```bash39curl https://api.openai.com/v1/models \40 -H "Authorization: Bearer $OPENAI_API_KEY" \41 -H "OpenAI-Organization: $ORGANIZATION_ID" \42 -H "OpenAI-Project: $PROJECT_ID"43```4445Usage from these API requests counts as usage for the specified organization and project. Find organization and project IDs in your [dashboard settings](https://platform.openai.com/settings/organization/general).4647## Request headers4849For reliable behavior across API paths and HTTP versions, keep the total size50of an API request's headers under 64 KiB. This budget includes the names and51values of all headers, including common headers such as `Authorization`,52`Content-Type`, and `User-Agent`, as well as any custom headers.5354To leave room for required headers and headers added by intermediaries, keep55any individual custom header value and the total size of all custom header56values at 60 KiB or less. Requests with larger headers may fail before they57reach the API, so you may not receive a response or an `x-request-id`.5859## Debugging requests6061[Error codes](https://developers.openai.com/api/docs/guides/error-codes) describe failures returned from API responses. Inspect HTTP response headers for the unique ID of a request and rate limit details. Common response headers include:6263**API meta information**6465- `openai-organization`: The [organization](https://developers.openai.com/api/docs/guides/production-best-practices#setting-up-your-organization) associated with the request66- `openai-processing-ms`: Time taken processing your API request67- `openai-version`: REST API version used for this request (currently `2020-10-01`)68- `x-request-id`: Unique identifier for this API request (used in troubleshooting)6970**[Rate limiting information](https://developers.openai.com/api/docs/guides/rate-limits)**7172- `x-ratelimit-limit-requests`73- `x-ratelimit-limit-tokens`74- `x-ratelimit-remaining-requests`75- `x-ratelimit-remaining-tokens`76- `x-ratelimit-reset-requests`77- `x-ratelimit-reset-tokens`78- `x-ratelimit-limit-project-tokens`79- `x-ratelimit-remaining-project-tokens`80- `x-ratelimit-reset-project-tokens`8182Project-token headers may be present when a project-scoped token limit applies.8384**OpenAI recommends logging request IDs in production deployments** for more efficient troubleshooting with the [support team](https://help.openai.com/en/), should the need arise. Official [client libraries](https://developers.openai.com/api/docs/libraries) provide a property on top-level response objects containing the value of the `x-request-id` header.8586### Supplying your own request ID with `X-Client-Request-Id`8788Along with the server-generated `x-request-id`, you can supply your own unique identifier for each request via the `X-Client-Request-Id` request header. This header isn't added automatically; you must explicitly set it on the request.8990When you include `X-Client-Request-Id`:9192- You control the ID format (for example, a UUID or your internal trace ID), but it must contain only ASCII characters and be no more than 512 characters long; otherwise, the request will fail with a 400 error. Make this value unique per request.9394- OpenAI logs this value internally for supported endpoints, including chat/completions, embeddings, responses, and more.9596- In cases like timeouts or network issues when you can't get the `X-Request-Id` response header, you can share the `X-Client-Request-Id` value with the support team to look up whether OpenAI received the request and when.9798**Example:**99100```bash101curl https://api.openai.com/v1/chat/completions \102 -H "Authorization: Bearer $OPENAI_API_KEY" \103 -H "X-Client-Request-Id: 123e4567-e89b-12d3-a456-426614174000"104```105106## Backwards compatibility107108OpenAI provides stability to API users by avoiding breaking changes in major API versions whenever reasonably possible. This includes:109110- The REST API (currently `v1`)111- First-party [client libraries](https://developers.openai.com/api/docs/libraries) (released libraries adhere to [semantic versioning](https://semver.org/))112- [Model](https://developers.openai.com/api/docs/models) families (like `gpt-4o` or `o4-mini`)113114**Model prompting behavior between snapshots is subject to change**.115Model outputs are by their nature variable, so expect changes in prompting and model behavior between snapshots. The best way to ensure consistent prompting behavior and model output is to use pinned model versions, and to run [evals](https://developers.openai.com/api/docs/guides/evals) for your applications.116117**Backwards-compatible API changes**:118119- Adding new resources (URLs) to the REST API and client libraries120- Adding new optional API parameters121- Adding new properties to JSON response objects or event data122- Changing the order of properties in a JSON response object123- Changing the length or format of opaque strings, like resource identifiers124- Adding new event types in streaming APIs125126See the [changelog](https://developers.openai.com/api/docs/changelog) for a list of backwards-compatible changes and rare breaking changes.