Skip to content
Docs ·Chat API

Chat API

Request and response formats, and streaming

POST https://alprouter.com/api/v1/chat/completions looks similar to OpenAI’s Chat Completions.

Requests

ItemValueExplanation/Description
modelText/TextModel name. If “alprouter/auto” is entered, it will be selected automatically.
messagesList/ListingsDialogue. The role involves handling systems, developers, users, assistants, and tools.
modelsList/ListingsWhen the model gets stuck, use the models one by one. Up to 5 models can be used at a time.
streamtrue · falseWill it be accepted as it is?
max_tokensNumbersThe maximum length that can be created. It’s the same as “max_completion_tokens”.
n1~4Let’s come up with a few answers. I’ll just use the models that are given to me.
tools · tool_choiceList · ValuesTools that the model can use
response_formatObjectsIt’s received in a format that’s predefined, just like JSON.
reasoning_effort · reasoningText · ObjectsHow deeply one will think about it…
providerObjectsTerms and conditions of the supplier
pluginsList/ListingsAuto-router settings

When you omit max_tokens, the limit is the smaller of 32,768 tokens and the amount your remaining credits can cover. See Model parameters for model-specific options such as temperature.

See Amem AI memory for how to include a user’s preferences in a request.

Responses

{
  "id": "gen-…",
  "object": "chat.completion",
  "model": "anthropic/claude-opus-5.5",
  "provider": "Amazon Bedrock",
  "choices": [{
    "index": 0,
    "message": { "role": "assistant", "content": "Hello!" },
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 5,
    "total_tokens": 17,
    "prompt_tokens_details": { "cached_tokens": 0, "cache_write_tokens": 0 },
    "completion_tokens_details": { "reasoning_tokens": 0 },
    "cost": 0.0000037
  }
}
  • model and provider actually represent the models and suppliers that were actually used. If you use automatic selection or scrolling, the values may differ from those requested.
  • usage.cost represents the cost associated with this request, in dollars. One dollar is equivalent to 1,620 credits.
  • There’s the same ID in the response header x-request-id. If you can provide this value during the request, it will make it easier to find the corresponding information.

Streaming

If you turn on stream, it will generate the results. If you also turn on stream_options.include_usage, then the last piece will include information about the usage and costs involved.

stream = client.chat.completions.create(
    model="anthropic/claude-opus-5.5",
    messages=[{"role": "user", "content": "Hello"}],
    stream=True,
    stream_options={"include_usage": True},
)
for chunk in stream:
    if chunk.choices:
        print(chunk.choices[0].delta.content or "", end="")
    elif chunk.usage:
        print("\npricing(USD):", chunk.usage.cost)
  • Each piece starts with a line that begins with “data: ”, and the last piece ends with “data: [DONE]”.
  • When I’m trying to get an answer, if there’s a problem, then error is sent. At that time, [DONE] doesn’t arrive.
  • If the connection is terminated during the process, the request will be stopped, and only the amount of time it took to complete the process will be charged. Depending on the model and the length of the input, the amount charged will be equal to the time it took to complete the process. For more details, please refer to Fees.