Skip to content

Text Generation

1. Get List of Available Models

GET /v1/models

List All Currently Available Models and Provide Basic Information About Each Model

Response (200)

json
{
  "object": "list",
  "data": [
    {
      "id": "gpt-4o",
      "object": "model",
      "created": 1686935002,
      "owned_by": "openai",
      "permission": [
        {
          "id": "modelperm-abc123",
          "object": "model_permission",
          "created": 1686935002,
          "allow_create_engine": false,
          "allow_sampling": true,
          "allow_logprobs": true,
          "allow_search_indices": false,
          "allow_view": true,
          "allow_fine_tuning": false,
          "organization": "*",
          "group": null,
          "is_blocking": false
        }
      ],
      "root": "gpt-4o",
      "parent": null
    },
    {
      "id": "gpt-4-vision-preview",
      "object": "model",
      "created": 1698357334,
      "owned_by": "openai",
      "permission": [
        {
          "id": "modelperm-def456",
          "object": "model_permission",
          "created": 1698357334,
          "allow_create_engine": false,
          "allow_sampling": true,
          "allow_logprobs": true,
          "allow_search_indices": false,
          "allow_view": true,
          "allow_fine_tuning": false,
          "organization": "*",
          "group": null,
          "is_blocking": false
        }
      ],
      "root": "gpt-4-vision-preview",
      "parent": null
    }
  ]
}

2. Conversation API

POST /v1/chat/completions

Create a Chat Completion with Model Response

Request Body

json
{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant. "
    },
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Analyze the content in this image"
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://example.com/image.jpg"
          }
        }
      ]
    }
  ],
  "max_tokens": 500,
  "temperature": 0.7,
  "stream": false
}

Parameter Description

  • model(Required):The model ID to be used, such as "gpt-4o", "gpt-4-vision-preview", etc.
  • messages(Required):An array of conversation messages, including roles and content
    • role(Required):The message role, which can be "system", "user", "assistant", or "tool"
    • content(Required):The message content, which can be a string or an array containing multimodal content
      • Text Content:{"type": "text", "text": "Text Content"}
      • Image Content:{"type": "image_url", "image_url": {"url": "Image URL", "detail": "auto|high|low"}}
      • Video Content:{"type": "video_url", "video_url": {"url": "Video URL"}}
  • max_tokens(Optional):The maximum number of tokens to generate; the default is unlimited
  • temperature(Optional):Sampling temperature, ranging between 0 and 2; the default is 1
  • stream(Optional):Whether to return partial results in a streaming manner; the default is false
  • top_p(Optional):Nucleus sampling; the default is 1
  • n(Optional):The number of chat completion choices to generate for each input message; the default is 1
  • stop(Optional): Sequences at which generation stops, which can be a string or an array of strings
  • presence_penalty(Optional):Penalty for the emergence of new topics, ranging between -2.0 and 2.0; the default is 0
  • frequency_penalty(Optional):Penalty for repetition based on existing frequency, ranging between -2.0 and 2.0; the default is 0
  • logit_bias(Optional):Modifies the likelihood of specific tokens appearing; the default is an empty object
  • user(Optional):A unique identifier representing the end user
  • response_format(Optional):Specifies the response format, e.g., {"type": "json_object"}

Response (200)

json
{
  "id": "chatcmpl-123abc",
  "object": "chat.completion",
  "created": 1677858242,
  "model": "gpt-4o",
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "This image shows an orange cat resting on the grass. It looks very relaxed, with sunlight shining on its fur. The background is a green grassland with a few small flowers."
      },
      "finish_reason": "stop",
      "index": 0
    }
  ],
  "usage": {
    "prompt_tokens": 82,
    "completion_tokens": 76,
    "total_tokens": 158
  }
}