Messages API
Send a structured list of messages and get a model-generated response in Anthropic format.
Create a message
POST
/anthropic/v1/messages
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Required | The model to use (e.g. "hacxgpt"). See /anthropic/v1/models for available options. |
messages | array | Required | A list of messages. Each message has a role and content. Content can be text, image, or tool use. |
max_tokens | integer | Required | Maximum number of tokens to generate. |
system | string/array | Optional | System prompt. Can be a string or an array of content blocks. |
temperature | number | Optional | Sampling temperature between 0 and 1. Default: 1. |
top_p | number | Optional | Nucleus sampling parameter. Default: 1. |
stop_sequences | array | Optional | Custom stop sequences. The model stops on these sequences. |
stream | boolean | Optional | If true, the response is streamed as SSE events. Default: false. |
tools | array | Optional | Tool definitions the model can use. |
tool_choice | object | Optional | Controls tool usage. { type: "auto" | "any" | "tool", name?: string }. |
Request
from anthropic import Anthropic
client = Anthropic(
api_key="hk-proj-YOUR_API_KEY",
base_url="https://api.hacxgpt.com/anthropic"
)
message = client.messages.create(
model="hacxgpt",
max_tokens=1024,
system="You are a helpful assistant.",
messages=[
{"role": "user", "content": "What is the capital of France?"}
]
)
print(message.content[0].text)Response
Response
{
"id": "msg_abc123",
"type": "message",
"role": "assistant",
"model": "hacxgpt",
"content": [
{
"type": "text",
"text": "Hello! How can I help you today?"
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 10,
"output_tokens": 8
}
}Streaming
Set stream: true to receive the response as SSE events. The stream follows the Anthropic SSE format with events: message_start, content_block_start, content_block_delta, content_block_stop, message_delta, message_stop.
with client.messages.stream(
model="hacxgpt",
max_tokens=1024,
messages=[{"role": "user", "content": "Tell me a story"}]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)Tip
The Messages API supports tool calling, vision (images as base64 or URLs), and multi-content blocks in messages. All features work the same as the official Anthropic API.