OpenAI API

OpenAI offers developer REST, streaming, and realtime APIs including the unified Responses API, legacy Chat Completions, Embeddings, Image generation, Audio (TTS/transcription), and Assistants with Threads/Runs. Base URL is https://api.openai.com/v1 and authentication uses Bearer tokens. Usage and rate limits vary by account tier and model; see official rate limit docs and your account console.

基础 URL
https://api.openai.com/v1
认证
Bearer / Authorization: Bearer $OPENAI_API_KEY
官方 SDK
Python, Node.js
🔑 API Key 获取
前置要求:Requires a valid account in supported regions; verify email/phone and add billing to increase quota and rate limits.
入口:https://platform.openai.com/api-keys
说明:Create or sign in to an OpenAI account, go to the platform console 'API keys' page, and click 'Create new secret key' to generate a key (shown only once).

支持模型

API 接口列表

GET /v1/models Docs

List available models and their metadata.

认证Yes
频率限制60/min
计费模式免费列举;实际计费取决于后续调用的具体模型与端点
curl https://api.openai.com/v1/models -H 'Authorization: Bearer $OPENAI_API_KEY'
POST /v1/responses Docs

Unified Responses API for conversational and tool-use generation tasks.

认证Yes
频率限制60/min
计费模式按模型令牌计费(输入/输出分开计费);Responses 不单独计价
{
  "model": "gpt-4.1",
  "input": "Say hello to the world"
}
POST /v1/chat/completions Docs

Chat Completions (legacy) supporting message arrays and streaming.

认证Yes
频率限制60/min
计费模式按模型令牌计费(输入/输出分开计费)
{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "Give me a quick example."
    }
  ],
  "stream": true
}
POST /v1/embeddings Docs

Create text embeddings for retrieval and similarity operations.

认证Yes
频率限制60/min
计费模式按模型令牌计费(通常仅输入计费)
{
  "model": "text-embedding-3-large",
  "input": "The quick brown fox jumps over the lazy dog"
}
POST /v1/images/generations Docs

Image generation (gpt-image-1 / DALL·E) with size and output format options.

认证Yes
频率限制60/min
计费模式按模型令牌与图片输出计费(详见价格页面)
{
  "model": "gpt-image-1",
  "prompt": "A cute baby sea otter",
  "n": 1,
  "size": "1024x1024"
}
POST /v1/audio/transcriptions Docs

Audio transcription (Whisper / 4o-transcribe family); upload audio and receive text.

认证Yes
频率限制60/min
计费模式按模型令牌计费;大文件可能需分片或批处理
{
  "model": "whisper-1",
  "file": "@/path/to/audio.mp3"
}
POST /v1/threads/{thread_id}/runs Docs

Create a Run on a given Thread for Assistants workflow execution.

认证Yes
频率限制60/min
计费模式按模型令牌计费(工具调用与检索可能产生额外费用)
{
  "assistant_id": "asst_XXXX",
  "instructions": "Answer with concise bullet points."
}