Chat Completions

Send a list of messages and get a model-generated response.

Create chat completion

POST
/v1/chat/completions
ParameterTypeRequiredDescription
modelstringRequiredThe model to use (e.g. "hacxgpt"). See /v1/models for available options.
messagesarrayRequiredA list of messages in the conversation. Each message has a role (system, user, assistant, tool) and content.
temperaturenumberOptionalSampling temperature between 0 and 2. Higher values produce more random outputs. Default: 1.
max_tokensintegerOptionalMaximum number of tokens to generate in the response.
streambooleanOptionalIf true, the response is streamed as SSE chunks. Default: false.
top_pnumberOptionalNucleus sampling parameter. Use temperature or top_p, but not both. Default: 1.
stopstring/arrayOptionalUp to 4 sequences where the API will stop generating further tokens.
toolsarrayOptionalA list of tool definitions the model may call.
tool_choicestring/objectOptionalControls which tool is called. "auto", "none", "required", or specify a tool.
response_formatobjectOptionalSpecify the output format. Use {"type": "json_object"} for JSON mode.
seedintegerOptionalSeed for deterministic sampling. Best-effort determinism.

Request

from openai import OpenAI

client = OpenAI(
    api_key="hk-proj-YOUR_API_KEY",
    base_url="https://api.hacxgpt.com/v1"
)

response = client.chat.completions.create(
    model="hacxgpt",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is the capital of France?"}
    ],
    temperature=0.7
)

print(response.choices[0].message.content)

Response

Response
{
  "id": "chatcmpl-a1b2c3d4e5f6",
  "object": "chat.completion",
  "created": 1710000000,
  "model": "hacxgpt",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 10,
    "completion_tokens": 8,
    "total_tokens": 18
  }
}

Streaming

Set stream: true to receive tokens as they're generated. The response is sent as server-sent events (SSE) with data: [DONE] signaling completion.

stream = client.chat.completions.create(
    model="hacxgpt",
    messages=[{"role": "user", "content": "Tell me a story"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

SSE Format

SSE Stream
data: {"id":"chatcmpl-a1b2c3d4","object":"chat.completion.chunk","created":1710000000,"model":"hacxgpt","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}

data: {"id":"chatcmpl-a1b2c3d4","object":"chat.completion.chunk","created":1710000000,"model":"hacxgpt","choices":[{"index":0,"delta":{"content":"Hello!"},"finish_reason":null}]}

data: {"id":"chatcmpl-a1b2c3d4","object":"chat.completion.chunk","created":1710000000,"model":"hacxgpt","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]
Tip
The API supports tool calling, JSON mode (response_format: { type: "json_object" }), and vision (images as base64 or URLs in the content array). All features work the same as the official OpenAI API.