Skip to content

OpenAI API

by openai.com

API keyHTTPSCORSMachine Learning
Open documentation ↗

Overview

Use AI models such as ChatGPT or DALL-E to experience the capabilities of AI

OpenAI is a machine learning API from openai.com. Requests are authenticated with an API key. It is served over HTTPS and allows browser requests (CORS). Its OpenAPI description documents 28 endpoints.

At a glance

Authentication
API key
HTTPS
Yes
CORS
Yes
Base URL
https://api.openai.com/v1
Version
1.2.0
Endpoints
28
Spec updated
2023-03-03

Make a first request

Replace the placeholders; the documentation says exactly where credentials go.

cURL
curl -X GET "https://api.openai.com/v1/files" \
  -H "Accept: application/json" \
  -H "X-API-Key: YOUR_API_KEY"
JavaScript
const response = await fetch("https://api.openai.com/v1/files", {
  method: "GET",
  headers: {
    "Accept": "application/json",
    "X-API-Key": "YOUR_API_KEY",
  },
});
const data = await response.json();
console.log(data);
Python
import requests

response = requests.request(
    "GET",
    "https://api.openai.com/v1/files",
    headers={
    "Accept": "application/json",
    "X-API-Key": "YOUR_API_KEY",
    },
    timeout=30,
)
print(response.json())

Endpoints

MethodPathWhat it does
POST/answersdeprecatedAnswers the specified question using the provided documents and examples. The endpoint first [searches](/docs/api-reference/searches) over provided documents o
POST/audio/transcriptionsTranscribes audio into the input language.
POST/audio/translationsTranslates audio into into English.
POST/chat/completionsCreates a completion for the chat message
POST/classificationsdeprecatedClassifies the specified `query` using provided examples. The endpoint first [searches](/docs/api-reference/searches) over the labeled examples to select the o
POST/completionsCreates a completion for the provided prompt and parameters
POST/editsCreates a new edit for the provided input, instruction, and parameters.
POST/embeddingsCreates an embedding vector representing the input text.
GET/enginesdeprecatedLists the currently available (non-finetuned) models, and provides basic information about each one such as the owner and availability.
GET/engines/{engine_id}deprecatedRetrieves a model instance, providing basic information about it such as the owner and availability.
POST/engines/{engine_id}/searchdeprecatedThe search endpoint computes similarity scores between provided query and documents. Documents can be passed directly to the API if there are no more than 200 o
GET/filesReturns a list of files that belong to the user's organization.
POST/filesUpload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be u
GET/files/{file_id}Returns information about a specific file.
DELETE/files/{file_id}Delete a file.
GET/files/{file_id}/contentReturns the contents of the specified file
GET/fine-tunesList your organization's fine-tuning jobs
POST/fine-tunesCreates a job that fine-tunes a specified model from a given dataset. Response includes details of the enqueued job including job status and the name of the fi
GET/fine-tunes/{fine_tune_id}Gets info about the fine-tune job. [Learn more about Fine-tuning](/docs/guides/fine-tuning)
POST/fine-tunes/{fine_tune_id}/cancelImmediately cancel a fine-tune job.
GET/fine-tunes/{fine_tune_id}/eventsGet fine-grained status updates for a fine-tune job.
POST/images/editsCreates an edited or extended image given an original image and a prompt.
POST/images/generationsCreates an image given a prompt.
POST/images/variationsCreates a variation of a given image.
GET/modelsLists the currently available models, and provides basic information about each one such as the owner and availability.
GET/models/{model}Retrieves a model instance, providing basic information about the model such as the owner and permissioning.
DELETE/models/{model}Delete a fine-tuned model. You must have the Owner role in your organization.
POST/moderationsClassifies if text violates OpenAI's Content Policy

Questions

Does the OpenAI API need an API key?

Yes. The OpenAI API uses API key authentication; the documentation explains how to get credentials.

Can I call the OpenAI API from the browser?

Yes. The OpenAI API sends CORS headers, so a web page can call it directly with fetch().

Does the OpenAI API support HTTPS?

Yes, the OpenAI API is served over HTTPS.

How many endpoints does the OpenAI API have?

Its OpenAPI description lists 28 endpoints in version 1.2.0. All of them are shown on this page.

What are alternatives to the OpenAI API?

Other Machine Learning APIs include Dialogflow, Hugging Face, WolframAlpha, OpenRouter, Laya Decision Gateway.

Compare alternatives →

Listed from public-apis database (MIT), APIs.guru (CC0).