Messages

The messages format, with its token counter. It needs an anthropic-version header and an explicit max_tokens.

Every response on this page was returned by the API when the page was built.

POST /v1/messages

Create a message.

The messages format. max_tokens is required; system sits beside messages. Streaming sends message_start, content_block_delta… and message_stop.

Request body

FieldTypeNotes
model Requiredstring
max_tokens Requiredinteger At least 1.
messages Requiredarray of object
systemstring or array
temperaturenumber 0 to 1.
top_pnumber
top_kinteger
stop_sequencesarray of string
streamboolean
memory_scopestring
POST /v1/messagescurl
curl -X POST https://api.znsi.ai/v1/messages \
  -H "x-api-key: $ZNSI_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mugen-5",
    "max_tokens": 512,
    "system": "Be concise.",
    "messages": [
      {
        "role": "user",
        "content": "What is KIZUNA?"
      }
    ]
  }'
ResponseJSON
HTTP/1.1 200 OK
content-type: application/json
request-id: req_fbba190d794e712f92b3570c
x-ratelimit-remaining-requests: 15
x-znsi-neurons: 8750000000

{
  "content": [
    {
      "text": "KIZUNA's neural link relay is on the status page as its own component. Relay recalibration is maintenance, and the participants are told in advance.\n\nKIZUNA means bond. It is a minimally invasive neural lace and the relay that links it to MUGEN. Trial KZ-2 runs in Reno and Kobe with 212 participants.\n\nDr. Tomasz Wierzba leads the clinical work. Enquiries go to [email protected].",
      "type": "text"
    }
  ],
  "id": "msg_XeW2lnaz1YS8gLXtxtXmp6ZZ",
  "model": "mugen-5",
  "role": "assistant",
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "type": "message",
  "usage": {
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "input_tokens": 20,
    "output_tokens": 116,
    "service_tier": "standard"
  }
}
Response with "stream": trueSSE
HTTP/1.1 200 OK
content-type: text/event-stream; charset=utf-8
request-id: req_5f3d457d25c5ca9c25eb983d
x-ratelimit-remaining-requests: 14
x-znsi-neurons: 7669000000

event: message_start
data: {"message":{"content":[],"id":"msg_iL5u0vFWy7Vt87KPpVZog6Kc","model":"mugen-5","role":"assistant","stop_reason":null,"stop_sequence":null,"type":"message","usage":{"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"input_tokens":20,"output_tokens":1,"service_tier":"standard"}},"type":"message_start"}

event: content_block_start
data: {"content_block":{"text":"","type":"text"},"index":0,"type":"content_block_start"}

event: ping
data: {"type":"ping"}

event: content_block_delta
data: {"delta":{"text":"KIZU","type":"text_delta"},"index":0,"type":"content_block_delta"}

… 22 more events …

event: message_delta
data: {"delta":{"stop_reason":"end_turn","stop_sequence":null},"type":"message_delta","usage":{"output_tokens":48}}

event: message_stop
data: {"type":"message_stop"}

Errors

  • 400 Invalid request: a missing or invalid parameter, named in param.
  • 401 No key, or a key that is malformed, expired or revoked.
  • 404 Unknown route or model.
  • 413 Request body larger than 10 MB.
  • 429 Rate limited, or MUGEN is declining this caller for a while. See retry-after.

POST /v1/messages/count_tokens

Count tokens.

How many input tokens a messages request would use, by the same count as usage.

Request body

FieldTypeNotes
model Requiredstring
messages Requiredarray of object
systemstring or array
temperaturenumber 0 to 1.
top_pnumber
top_kinteger
memory_scopestring
POST /v1/messages/count_tokenscurl
curl -X POST https://api.znsi.ai/v1/messages/count_tokens \
  -H "x-api-key: $ZNSI_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mugen-5",
    "messages": [
      {
        "role": "user",
        "content": "What is KIZUNA?"
      }
    ]
  }'
ResponseJSON
HTTP/1.1 200 OK
content-type: application/json
request-id: req_891c8d5945cbf15c770b761f
x-ratelimit-remaining-requests: 13

{
  "input_tokens": 12
}

Errors

  • 400 Invalid request: a missing or invalid parameter, named in param.
  • 401 No key, or a key that is malformed, expired or revoked.
  • 404 Unknown route or model.
  • 413 Request body larger than 10 MB.
  • 429 Rate limited, or MUGEN is declining this caller for a while. See retry-after.