Velaron.AI

DocsAPI reference

Streaming

Set stream to true and the answer arrives as server-sent events, token by token. You are billed for what was produced, when it is done.

Streaming
curl -N https://velaron.ai/v1/chat/completions \
  -H "Authorization: Bearer $KREDIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "model": "velaron/test", "stream": true, "messages": [{ "role": "user", "content": "hi" }] }'

data: {"object":"chat.completion.chunk","choices":[{"delta":{"content":"Velaron.AI test: hi"}}]}
data: {"object":"chat.completion.chunk","choices":[{"delta":{},"finish_reason":"stop"}]}
data: {"id":"kredit-charge-1758560000000","object":"chat.completion.chunk","choices":[],"kredit":{"credits_charged":1,"balance":4999}}
data: [DONE]

How a stream is billed#

  • Before the first byte, Velaron.AI places a hold on your balance for the most the answer could cost. The hold is released the moment the stream settles, and GET /v1/account shows it under held while a call is running.
  • When the stream ends, the provider's reported usage is charged. If the provider reported none, the tokens are estimated from the text that was produced.
  • If you disconnect early, the charge is settled at that moment for what was produced up to then. Nothing is charged for output that never happened.
  • The provider's events are forwarded line by line; keep-alive comments are passed through.

Where the charge is reported#

Response headers are sent before the answer exists, so a proxied stream cannot carry x-vels-credits-charged. Instead:

EndpointIn-band report
/v1/chat/completionsOne extra chunk before data: [DONE], with an empty choices array and a kredit object holding credits_charged and balance. Clients that ignore unknown fields never notice it.
/v1/responsesNone. Read the balance from GET /v1/account afterwards.
/v1/messagesNone. Read the balance from GET /v1/account afterwards.