Skip to main content
POST
/
v1
/
chat
/
completions
Create chat completion
curl --request POST \
  --url https://api.example.com/v1/chat/completions \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "<string>",
  "messages": [
    {
      "tool_calls": [
        {
          "id": "<string>",
          "index": 123,
          "type": "<string>",
          "function": {
            "name": "<string>",
            "arguments": "<string>"
          }
        }
      ],
      "tool_call_id": "<string>",
      "reasoning_content": "<string>",
      "content": {},
      "name": "<string>",
      "refusal": "<string>",
      "annotations": [
        {}
      ]
    }
  ],
  "stream_options": {
    "include_usage": true
  },
  "top_p": 123,
  "max_tokens": 123,
  "max_completion_tokens": 123,
  "frequency_penalty": 123,
  "presence_penalty": 123,
  "logit_bias": {
    "key": 123
  },
  "top_logprobs": 123,
  "response_format": {
    "json_schema": {
      "name": "<string>",
      "description": "<string>",
      "schema": {},
      "strict": true
    },
    "type": "<string>"
  },
  "prompt_cache_key": "<string>",
  "prompt_cache_retention": "<string>",
  "safety_identifier": "<string>",
  "tool_choice": {},
  "parallel_tool_calls": true,
  "service_tier": "<string>",
  "reasoning_effort": "<string>",
  "web_search_options": {},
  "function_call": {},
  "stream": true,
  "temperature": 123,
  "stop": {},
  "n": 123,
  "logprobs": true,
  "seed": 123,
  "user": "<string>",
  "tools": [
    {
      "type": "<string>",
      "function": {
        "name": "<string>",
        "description": "<string>",
        "parameters": {},
        "strict": true
      }
    }
  ],
  "modalities": [
    "<string>"
  ],
  "audio": {},
  "metadata": {
    "key": "<string>"
  },
  "prediction": {},
  "verbosity": "<string>",
  "functions": [
    {}
  ]
}
'
{
  "system_fingerprint": "<string>",
  "service_tier": "<string>",
  "id": "<string>",
  "object": "<string>",
  "created": 123,
  "model": "<string>",
  "choices": [
    {
      "finish_reason": "<string>",
      "index": 123,
      "message": {
        "tool_calls": [
          {
            "id": "<string>",
            "index": 123,
            "type": "<string>",
            "function": {
              "name": "<string>",
              "arguments": "<string>"
            }
          }
        ],
        "tool_call_id": "<string>",
        "reasoning_content": "<string>",
        "content": {},
        "name": "<string>",
        "refusal": "<string>",
        "annotations": [
          {}
        ]
      },
      "logprobs": {
        "content": [
          {
            "top_logprobs": [
              {
                "token": "<string>",
                "logprob": 123,
                "bytes": [
                  123
                ]
              }
            ],
            "token": "<string>",
            "logprob": 123,
            "bytes": [
              123
            ]
          }
        ],
        "refusal": [
          {
            "top_logprobs": [
              {
                "token": "<string>",
                "logprob": 123,
                "bytes": [
                  123
                ]
              }
            ],
            "token": "<string>",
            "logprob": 123,
            "bytes": [
              123
            ]
          }
        ]
      }
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123,
    "prompt_tokens_details": {
      "cached_tokens": 123,
      "audio_tokens": 123
    },
    "completion_tokens_details": {
      "reasoning_tokens": 123,
      "audio_tokens": 123,
      "accepted_prediction_tokens": 123,
      "rejected_prediction_tokens": 123
    },
    "ephemeral_5m_input_tokens": 123,
    "ephemeral_1h_input_tokens": 123,
    "web_search_requests": 123
  }
}
This endpoint is compatible with the OpenAI Chat Completions protocol for creating chat completion requests.

Features

  • Supports both streaming (SSE) and non-streaming response modes
  • Supports multimodal input (text, images, etc.)
  • Supports function calling and tool calling
  • Supports structured output (JSON Schema)
  • Supports reasoning effort configuration
  • Supports web search options

Use cases

Suitable for scenarios requiring interaction with OpenAI-compatible models, including:
  • Single-turn or multi-turn conversations
  • Function calling and tool orchestration
  • Structured JSON output
  • Real-time streaming responses

Authentication

Include the Authorization header in the format Bearer YOUR_API_KEY.
Never expose API keys in client-side code. Use a server-side proxy to forward requests.

Quick example

import requests

url = "https://api.haitoken.ai/v1/chat/completions"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}
data = {
    "model": "gpt-4o",
    "messages": [
        {"role": "user", "content": "Hello, please introduce yourself"}
    ]
}

response = requests.post(url, json=data, headers=headers)
print(response.json())

Headers

Authorization
string
required
Example:

"Bearer YOUR_API_KEY"

Content-Type
string
Example:

"application/json"

Body

application/json
model
string
required

Model ID, e.g. gpt-4o, deepseek-chat, etc.

messages
object[]
required

List of messages

stream_options
object

Streaming response options (only used when stream=true)

top_p
number

Nucleus sampling, between 0 and 1

max_tokens
integer

Maximum number of tokens to generate (deprecated, use max_completion_tokens instead)

max_completion_tokens
integer

Maximum number of tokens to generate (including visible output tokens and reasoning tokens)

frequency_penalty
number

Frequency penalty, -2.0 to 2.0

presence_penalty
number

Presence penalty, -2.0 to 2.0

logit_bias
object

Map to modify the likelihood of specified tokens appearing

top_logprobs
integer

Maximum number of most likely tokens to return at each token position (0-20)

response_format
object

Response format, supports "text", "json_object", "json_schema"

prompt_cache_key
string

Stable identifier for cache optimization

prompt_cache_retention
string

Cache retention policy: "in_memory" or "24h"

safety_identifier
string

Safety identifier for detecting violating users

tool_choice
object

Controls which tool the model calls, can be a string ("none"/"auto"/"required") or an object

parallel_tool_calls
boolean

Whether to enable parallel tool calls

service_tier
string

Service tier: "auto", "default", "flex", "scale", "priority"

reasoning_effort
string

Reasoning effort level: "none", "minimal", "low", "medium", "high", "xhigh"

web_search_options
object

Web search options

function_call
object

Deprecated: function call control

stream
boolean

Whether to enable streaming output

temperature
number

Sampling temperature, between 0 and 2, higher values produce more random output

stop
object

Stop sequences

n
integer

Number of chat completion choices to generate for each input message

logprobs
boolean

Whether to return log probabilities of output tokens

seed
integer<int64>

Seed value for deterministic sampling

user
string

User identifier (deprecated, use prompt_cache_key instead)

tools
object[]

List of tools the model can call

modalities
string[]

Output type list: ["text"] or ["text", "audio"]

audio
object

Audio output parameters

metadata
object

Metadata, up to 16 key-value pairs

prediction
object

Predicted output content

verbosity
string

Response verbosity: "low", "medium", "high"

functions
object[]

Deprecated: list of function definitions

Response

200 - application/json

OpenAI Chat Completions API response object

system_fingerprint
string

System fingerprint, representing backend configuration

service_tier
string

Actual service tier used

id
string

Unique identifier for the chat completion

object
string

Object type, always "chat.completion"

created
integer<int64>

Creation time (Unix timestamp)

model
string

Model ID used

choices
object[]

List of chat completion choices

usage
object

Usage statistics