Messages API

Send a structured list of messages and get a model-generated response in Anthropic format.

Create a message

POST
/anthropic/v1/messages
ParameterTypeRequiredDescription
modelstringRequiredThe model to use (e.g. "hacxgpt"). See /anthropic/v1/models for available options.
messagesarrayRequiredA list of messages. Each message has a role and content. Content can be text, image, or tool use.
max_tokensintegerRequiredMaximum number of tokens to generate.
systemstring/arrayOptionalSystem prompt. Can be a string or an array of content blocks.
temperaturenumberOptionalSampling temperature between 0 and 1. Default: 1.
top_pnumberOptionalNucleus sampling parameter. Default: 1.
stop_sequencesarrayOptionalCustom stop sequences. The model stops on these sequences.
streambooleanOptionalIf true, the response is streamed as SSE events. Default: false.
toolsarrayOptionalTool definitions the model can use.
tool_choiceobjectOptionalControls 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.