How tokens are counted & credits are charged — per model

This document explains, for the Rayu‑hosted (paid) models, exactly how token usage is turned into a credit charge, and the per‑model rate for every model currently offered.

TL;DR

  • 1 credit = 1,000,000 tokens (the reference rate).
  • Every model has a rate = credits per 1,000,000 tokens (its creditMultiplier).
  • You are charged: credits = tokens_used × rate ÷ 1,000,000, where tokens_used is the actual input + output tokens the model reported.
  • A failed or unavailable request costs 0 credits.

For the underlying mechanism (reserve/settle, cache‑aware billing, the Redis counter), see credits-and-limits.md.


1. The charge formula

Charging happens in the gateway, off the model's real usage — not an estimate. For the active hosted models (served via Ollama Cloud), billing is flat: input tokens and output tokens are charged at the same rate, and there is no prompt‑cache discount, so:

billable_tokens = (input_tokens + output_tokens) × rate
credits_charged = billable_tokens ÷ 1,000,000
              = tokens_used × rate ÷ 1,000,000

rate is the model's credits‑per‑1M‑tokens value (the creditMultiplier). Because 1 credit = 1,000,000 tokens, the rate reads directly as “credits per million tokens”.

  • rate = 1.0 → 1,000,000 tokens costs 1 credit
  • rate = 2.5 → 1,000,000 tokens costs 2.5 credits
  • rate = 0.75 → 1,000,000 tokens costs 0.75 credits

Only tokens the provider actually reports are counted; the display in /usage shows the real tokens used, not a rounded‑up number.


2. Per‑model rates

Rates below are the current defaults. All of them are admin‑editable in the dashboard (Models → per‑model creditMultiplier); nothing here is hard‑coded into the charge.

Model (id)Served viaRate — credits / 1M tokensContext windowStatus
DeepSeek V4 Flash (deepseek-v4-flash)DeepSeek API0.331MActive
DeepSeek V4 Pro (deepseek-v4-pro)DeepSeek API1.01MActive
GLM‑5.2 (glm-5.2)Ollama Cloud2.51MActive
Kimi K2.7 (kimi-k2.7)Ollama Cloud2.5256KActive
MiniMax M3 (minimax-m3)Ollama Cloud2.51MActive
Llama 4 (llama-4)Ollama Cloud1.01MActive
GPT‑OSS 120B (gpt-oss-120b)Ollama Cloud0.75128KActive
Qwen3.5 397B (qwen3.5-397b)Ollama Cloud0.75256KActive
Qwen3.5 122B (qwen3.5-122b)Ollama Cloud0.75256KActive
LongCat 2.0 (longcat-2)LongCat0.51MDisabled

Notes:

  • DeepSeek (official API) and Ollama Cloud are both active right now (LongCat's provider row has enabled = false in Admin → Providers). A disabled provider's models are hidden from users and any request to them is refused (with no charge). DeepSeek V4 Flash/Pro are served DIRECT through DeepSeek's own Anthropic-compatible API (provider deepseek); the remaining hosted models are served through Ollama Cloud.
  • MiniMax M3 and Llama 4 rates were not individually specified and use a sensible default (2.5 and 1.0) — adjust in the admin dashboard as needed.
  • Context window is what the CLI reports for the model (used for context management). If a model is served by an upstream with a smaller real window, set a per‑model context override to avoid overflow.

Rate tiers at a glance

  • 0.33 / 1M — DeepSeek V4 Flash (cheapest)
  • 0.75 / 1M — GPT‑OSS 120B, Qwen3.5 397B, Qwen3.5 122B
  • 1.0 / 1M — DeepSeek V4 Pro (reference), Llama 4
  • 2.5 / 1M — GLM‑5.2, Kimi K2.7, MiniMax M3

3. Worked examples

Assume the reference rate (1 credit = 1,000,000 tokens).

ModelTokens used (in + out)Charge
DeepSeek V4 Pro (1.0)1,000,0001.00 credit
DeepSeek V4 Pro (1.0)200,0000.20 credit
DeepSeek V4 Flash (0.33)1,000,0000.33 credit
GPT‑OSS 120B (0.75)1,000,0000.75 credit
GLM‑5.2 (2.5)1,000,0002.50 credits
GLM‑5.2 (2.5)40,000 (a small turn)0.10 credit

A trivial message (e.g. a few thousand tokens) costs a tiny fraction of a credit — it is not rounded up to a whole credit.


4. What a plan buys

A plan grants a credit allowance per billing period (creditsPerPeriod). Because 1 credit = 1,000,000 tokens, the allowance converts to tokens per model by dividing by the model's rate.

Example — a plan with 50 credits / period:

If you only used…You'd get about…
DeepSeek V4 Pro (1.0)50,000,000 tokens (50 credits ÷ 1.0)
DeepSeek V4 Flash (0.33)~151,000,000 tokens (50 ÷ 0.33)
GPT‑OSS 120B (0.75)~66,000,000 tokens (50 ÷ 0.75)
GLM‑5.2 (2.5)20,000,000 tokens (50 ÷ 2.5)

Credits deplete over the period and reset at renewal. When the balance is exhausted, further hosted requests return a credit‑limit error (or draw from top‑up credits if the plan enables top‑up). Plan credit amounts and prices are admin‑configured — see credits-and-limits.md.


5. Edge cases (what you are NOT charged for)

  • Failed / errored request — if the upstream fails, usage settles to the real amount (0 for a failed turn), so a failed request costs 0 credits.
  • Disabled provider — a request for a model whose provider is turned off returns 503 before any reserve, so it charges 0 credits and does not consume a daily turn.
  • Rate‑limited key — the gateway rotates/fails over across the provider's keys automatically; you are only charged for the request that actually succeeds, at the model's rate.

6. Where the numbers live (admin‑editable)

WhatWhere
Per‑model rate (creditMultiplier) + pricesAdmin → Models (hosted_models table)
1 credit = 1,000,000 tokens baseline (baselineCreditsPer1M)Admin → Credit Settings (app_settings)
Plan credit allowance (creditsPerPeriod)Admin → Plans
Which providers are activeAdmin → Providers (providers.enabled)
Where/how a provider is called (base URL, wire format, auth)Admin → Providers (providers table)
Per‑model capabilities (thinking, image input)Admin → Models (supportsReasoning / supportsImage)

The gateway computes every charge from these values at request time — changing a rate in the dashboard changes the charge with no code change or redeploy of the CLI. The CLI is display‑only; the gateway is the single source of truth for billing.