Endpoint and prerequisites
POST https://acosmi.com/v1/messages
Authenticate using a personal PAYG key with Authorization: Bearer and models:chat scope. The compatibility surface and selected anthropic profile must be available, with confirmed pricing, finance and release state in the catalog. Protocol compatibility does not imply every vendor API is supported.
Request fields
| Field | Type | Usage |
|---|---|---|
model | string | Selected profile UUID, not the display name |
messages | array | At least one message in this protocol’s format |
max_tokens | integer | Explicit positive value within the profile output limit; this example uses 64 |
stream | boolean | false for JSON, true for SSE |
temperature / top_p | number | Send only if declared; model-specific ranges apply |
tools / tool_choice | array / string or object | Only for supported configurations; protocol-specific shapes |
acosmi_options | object | Acosmi extensions for V2 price version and spending cap, as described below |
Use top-level system for the system prompt. Messages use user and assistant; the response contains a content block array and tool requests use tool_use blocks. Do not copy OpenAI tool_calls unchanged.
Follow supported_parameters on the model detail page. Current public text profiles declare max_tokens. Budget support differs across entry points; do not substitute max_completion_tokens or send both without confirming the endpoint contract.
V2 request template
Use this only with an available TEXT_COMPONENTS_V2 configuration. Provide its current positive price-version integer. A CNY 1 cap is the public Credits string "1000000".
: "${ACOSMI_API_KEY:?Set your personal PAYG key}"
: "${ACOSMI_MODEL_ID:?Set a callable V2 Anthropic profile UUID}"
: "${ACOSMI_PRICE_VERSION:?Set its current positive effective_price_version}"
curl --fail-with-body 'https://acosmi.com/v1/messages' \
-H "Authorization: Bearer $ACOSMI_API_KEY" \
-H 'Content-Type: application/json' \
--data-binary @- <<JSON
{"model":"$ACOSMI_MODEL_ID","messages":[{"role":"user","content":"Hello"}],"max_tokens":64,"stream":false,"acosmi_options":{"contract_version":"TEXT_COMPONENTS_V2","expected_price_version":${ACOSMI_PRICE_VERSION},"max_credits":"1000000"}}
JSONacosmi_options is not sent to the model vendor. A price-version change requires another decision, not an automatic budget increase. Legacy V1 total-token requests do not use these V2 fields; copy the template for the selected configuration.
Successful response
This abbreviated structure is illustrative, not a production receipt. Usage numbers demonstrate fields only:
{"type":"message","role":"assistant","content":[{"type":"text","text":"Hello!"}],"stop_reason":"end_turn","usage":{"input_tokens":12,"output_tokens":3}}Handle delivered output, stop reasons and financial status separately. A tool request is not an executed tool: validate the name and arguments, perform the authorized action, and return its result in the proper protocol. See tools and structured output.
Streaming and errors
With stream=true, consume text/event-stream. Anthropic uses events such as message_start, content_block_delta and message_stop, not OpenAI [DONE]. Heartbeats, errors and disconnections are not normal completion. See streaming.
Inspect the protocol error object for non-2xx responses. After streaming has begun, errors may appear inside events despite HTTP 200. Keep request IDs and follow error handling before repeating a request.
Related documentation
Models · Authentication · Billing · OpenAPI