api.openai.com

API REFERENCE

OpenAI Status

Models

List Models

# GET https://api.openai.com/v1/models
$ curl https://api.openai.com/v1/models \
  -H 'Authorization: Bearer YOUR_API_KEY'

$ curl -o openai-models.json https://api.openai.com/v1/models \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'OpenAI-Organization: YOUR_ORG_ID'

Retrieve model

# GET https://api.openai.com/v1/models/{model}
$ curl https://api.openai.com/v1/models/gpt-3.5-turbo \
  -H 'Authorization: Bearer YOUR_API_KEY'

$ curl https://api.openai.com/v1/models/text-davinci-003 \
  -H 'Authorization: Bearer YOUR_API_KEY'

$ curl https://api.openai.com/v1/models/code-davinci-002 \
  -H 'Authorization: Bearer YOUR_API_KEY'

$ curl https://api.openai.com/v1/models/code-cushman-001 \
  -H 'Authorization: Bearer YOUR_API_KEY'

Completions

Create completion

# POST https://api.openai.com/v1/completions
$ curl https://api.openai.com/v1/completions \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -d '{
  "model": "code-cushman-001",
  "prompt": "Python 3 Calculate the mean distance between an array of points",
  "max_tokens": 200,
  "temperature": 0
}'

Chat

# POST https://api.openai.com/v1/chat/completions
$ curl https://api.openai.com/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -d '{
  "model": "gpt-3.5-turbo",
  "messages": [
    {"role": "system", "content": "小红书的风格是:很吸引眼球的标题,每个段落都加 emoji, 最后加一些 tag。请用小红书风格"},
    {"role": "user", "content": "介绍下MacBook Pro 2022"}],
  "temperature": 0.7
}'