Skip to main content
POST
/
chat
/
completions
curl --request POST \
--url https://ai.megallm.io/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-4",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 123,
  "model": "gpt-4",
  "choices": [
    {
      "index": 123,
      "message": {
        "role": "system",
        "content": "<string>",
        "name": "<string>",
        "tool_calls": [
          {
            "id": "<string>",
            "type": "function",
            "function": {
              "name": "<string>",
              "arguments": "<string>"
            }
          }
        ],
        "tool_call_id": "<string>"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123
  }
}

Authorizations

Authorization
string
header
required

Bearer token authentication (OpenAI-compatible)

Body

application/json
model
string
required

Model ID (e.g., gpt-4, claude-3.5-sonnet)

Example:

"gpt-4"

messages
object[]
required

Array of message objects

temperature
number
default:0.7

Sampling temperature (0.0 - 2.0)

Required range: 0 <= x <= 2
max_tokens
integer

Maximum tokens to generate

stream
boolean
default:false

Enable streaming responses

tools
object[]

Available functions/tools

tool_choice

Controls tool calling behavior

Available options:
auto,
required,
none
top_p
number

Nucleus sampling parameter

Required range: 0 <= x <= 1
frequency_penalty
number
default:0

Penalize frequent tokens

Required range: -2 <= x <= 2
presence_penalty
number
default:0

Penalize repeated tokens

Required range: -2 <= x <= 2
n
integer
default:1

Number of completions to generate

stop

Stop sequences

user
string

Unique user identifier

Response

Successful response

id
string
Example:

"chatcmpl-abc123"

object
enum<string>
Available options:
chat.completion
created
integer

Unix timestamp

model
string
Example:

"gpt-4"

choices
object[]
usage
object