POST
/
v1
/
chat
/
completions
Web Search
curl --request POST \
  --url https://api.example.com/v1/chat/completions \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "<string>",
  "messages": [
    {}
  ],
  "temperature": 123,
  "max_tokens": 123,
  "stream": true,
  "web_search": true
}
'
{
  "id": "<string>",
  "object": "<string>",
  "created": 123,
  "model": "<string>",
  "choices": [
    {}
  ],
  "usage": {}
}
Chat completions interface enhanced with Web search functionality for real-time web information.

Overview

The Web Search interface allows AI models to access real-time web information when generating responses. This is particularly useful for queries that require up-to-date information.

Authentication

All requests require a Bearer token in the Authorization header:
Authorization: Bearer YOUR_API_KEY

Request Parameters

model
string
required
ID of the model to use. Models supporting Web search include GPT models with search capabilities.
messages
array
required
A list of messages comprising the conversation.
temperature
number
default:"1"
Sampling temperature between 0 and 2. Higher values make output more random, lower values make it more focused.
max_tokens
integer
Maximum number of tokens to generate.
stream
boolean
default:"false"
Whether to stream responses.
Whether to enable Web search functionality.

Request Example

curl -X POST https://api.example.com/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4-web",
    "messages": [
      {"role": "user", "content": "What are today news headlines?"}
    ],
    "web_search": true,
    "temperature": 0.7
  }'

Response Example

{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-4-web",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Based on the latest web search results, today's main news headlines include..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 15,
    "completion_tokens": 150,
    "total_tokens": 165
  }
}

Response Fields

id
string
Unique identifier for the completion.
object
string
Object type, which is chat.completion.
created
integer
Unix timestamp of when the completion was created.
model
string
The model used.
choices
array
List of completion choices.
usage
object
Usage statistics for the request.

Parameters

ParameterTypeRequiredDefaultDescription
modelstringYes-ID of the model to use
messagesarrayYes-List of messages in the conversation
temperaturenumberNo1Sampling temperature (0-2)
max_tokensintegerNo-Maximum tokens to generate
streambooleanNofalseEnable streaming responses
web_searchbooleanNotrueEnable Web search