Skip to content

Call a model from your program

Updated Nov 26, 2026
On this page

Your own program can send messages to a model of Raven and get its answer. Each call runs on a key in your provider profiles (Provider keys). The Usage page shows what the calls cost.

The base URL is https://api.cch137.com.

Before you start

  1. Create a token with the scope api in Settings → Credentials.
  2. Find a model in GET /v1/catalog/models. This list needs no token. A model's slug is its name in a request.
  3. Add a key for the provider of the model in Settings > Providers.

Authentication

Send the token in the header Authorization: Bearer <token>.

  • Only a token with the scope api can call this endpoint. Another token gets the same response as an invalid token.
  • Each api token can make 60 requests in 60 seconds. More requests get 429.
  • Keep the token on your server. A page in a browser cannot call this endpoint.

Request

POST /v1/ai/complete with a JSON body:

Field Required Value
label Yes The name of your program, such as my-app
idempotency_key Yes A new unique string for each call, such as a UUID
model Yes The slug of a model
messages Yes The conversation, oldest first. Each message is { "role", "content" }. role is user or assistant.
system No The instructions for the model
stream No true sends the answer as server-sent events. The default is false.
reasoning_effort No none, low, medium, high, xhigh or max. A model that does not support the effort uses its nearest effort below it, or else its lowest effort.
verbosity No low, medium or high, for a model that takes it
max_tokens No The largest number of tokens in the answer
json_schema No A JSON Schema object. The answer is then an object of that schema. You cannot use it with stream.
web_search No true lets the model search the web while it answers. The provider bills the searches on your key.
cache No true, or { "ttl": "5m" or "1h", "key": "..." }, to cache a beginning of the messages that you send again. The key is at most 256 bytes.

Do not send user_id. The call runs on the keys of the token owner. A body with user_id gets 400.

content is a string, or a list of these parts:

Part Value
{ "type": "text", "text": "..." } Text
{ "type": "image", "mime_type": "image/png", "data": "..." } A PNG or JPEG image in standard base64, in a user message only. mime_type is image/png or image/jpeg.

Limits:

Limit Value
Request body 2 MiB. Base64 makes an image about a third larger.
Images in one request 8
One image 5 MiB

Response

Without stream, a success is 200 with this JSON:

Field Value
request_id The id of the call
model The model that answered, as <provider>/<slug>
reasoning_effort The effort that the model used. Absent for a model without one.
text The answer
object The answer as an object, with json_schema, in place of text
usage { "input_tokens", "output_tokens", "credits" }, and cache_read and cache_write when the model reported them. credits is the list price of the call in units of 10⁻⁹ USD.
citations The web pages that the answer used, with web_search
replayed true when the answer comes from an earlier call with the same key

Stream

With "stream": true, the response is text/event-stream. The events come in this order:

Event Data
meta { "request_id", "model", "reasoning_effort" }. Another meta comes when a second model takes over before any text.
delta { "text" }: the next part of the answer
ping {}: the model works, but has no new text
usage The usage object of the response
done {}: the answer is complete
error { "code", "message" }: the call failed. The stream ends after it.

A call that started is billed in full, also when your program closes the connection. To get the answer after a disconnect, send the same request again. The finished answer comes back as JSON, not as a stream.

The same key again

Raven keeps each key for 24 hours. Your keys are separate from the keys of other accounts, and each label has its own keys.

You send the same key Result
After the call finished, with the same body The same answer, with replayed: true. You do not pay again.
While the call runs 409 aborted
After the call failed A new call
With a different body 400 invalid_request

Errors

An error response has this shape:

json
{ "error": { "code": "no_provider_key", "message": "No provider key for OpenAI. Add a key in Settings > Providers." } }
Status Code Cause
400 invalid_request A field is missing or not valid. The message names the field.
400 context_length The messages are too long for the model.
401 unauthenticated The token is missing, not valid, or has no api scope.
402 no_provider_key You have no key for the provider of the model, or none of your keys serves the model. The message names the provider or the model.
409 aborted A call with the same key still runs.
413 payload_too_large The body is larger than 2 MiB.
429 rate_limited The token made 60 requests in 60 seconds. Retry-After gives the seconds to wait.
429 rate_limit The model provider limits the calls now. Try again later.
502 auth, server, network, aborted or unknown The model provider failed.
503 overloaded The model or Raven is busy. Try again soon.
504 timeout The model did not answer in time.

The error event of a stream uses the same codes.

Example

sh
curl https://api.cch137.com/v1/ai/complete \
  -H "Authorization: Bearer $RAVEN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "label": "my-app",
    "idempotency_key": "6f0d2c1e-8a4b-4c2e-9b1d-3e5f7a9c0b12",
    "model": "claude-haiku-5-5",
    "system": "Translate the text into English.",
    "messages": [{ "role": "user", "content": "很高兴认识你。" }]
  }'

The response:

json
{
  "request_id": "0b7e4f7a-2a1c-4d8e-9f3b-5c6d7e8f9a0b",
  "model": "anthropic/claude-haiku-5-5",
  "text": "Nice to meet you.",
  "usage": { "input_tokens": 21, "output_tokens": 6, "credits": 48000 },
  "replayed": false
}