← Receivers

credits:spend

credits family

Record one model call's spend against YOUR workspace — priced by the one writer (sdk spend: tokens × the model's live rate), debited from the funding chain, emits credits.spent, closes with mark or warn (text/billing.md promise 3)

Effect
ask
Awaits an outcome — the call returns the response below.
Caller
member
The class of authority the caller must already hold, decided from the attested context with no round trip.
Cost
variable
What one call costs, so you can budget before acting.
Reversible
yes
The effect can be undone by a later call.
Idempotent
no
Not safe to blind-retry — dedupe on the envelope idempotencyKey.

Send it with your agent

One click hands your coding agent a prompt that registers the substrate, reads this contract, and makes the call. Launch opens the app; the others copy the prompt.

Claude Code
Codex
Cursor
Gemini CLI
Claude Desktop
ChatGPT
curl -X POST https://one.ie/api/ask/credits:spend \
  -H "Authorization: Bearer $ONE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"data": { "model": <string>, "tokensIn": <number>, "tokensOut": <number> }}'

The key is never in a link. npx -y @oneie/cli login writes it to ~/.config/oneie/key on your machine.

Request

Validated before dispatch — an invalid payload is refused with the fix, never half-applied.

  • model string required The model the call RAN on, e.g. 'deepseek/deepseek-v4-flash'. Priced from the live OpenRouter rate blob; an unknown id prices at the fallback and the row says rate_source='fallback'.
  • tokensIn number required Prompt tokens actually consumed.
  • tokensOut number required Completion tokens actually consumed, INCLUDING reasoning tokens.
  • reason agent_run | skill_call | inference optional What the call was for. Default agent_run.
  • threadId string optional The thread the call served, if any — carried on the credits.spent event.

Response

What comes back from the call.

  • ok boolean
  • credits number Credits charged (cost + margins).
  • costCredits number The upstream cost in credits, before margins.
  • recorded boolean true on a refusal: the tokens were already spent, so the row is written anyway and the balance goes negative.
  • error string unauthorized | invalid_request | nothing_to_spend | ledger_unavailable | meter_run_failed | 402 | floored | budget_exhausted | float_locked

Traffic

Every call to credits:spend, counted where it is dispatched — over HTTP or in-process alike. Aggregate only — no actor, no payload, no workspace.

Counting…

Wiring

Every place in the open source that names credits:spend, and the file that answers it. Read from the tree at build time — a receiver is reached by NAME through one door, so there is no import edge to follow and a grep is the honest shape of the question. Structure, not volume — the count is in Traffic above.

Called from

API route 1
  • one.ie/web/src/lib/receiver-index.generated.ts:96
→

Answered by

credits:spend one.ie/web/src/lib/resolvers/credits.ts:25 Dispatched through POST /api/ask/credits:spend, after the envelope validates the payload.
JSON Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "model": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "description": "The model the call RAN on, e.g. 'deepseek/deepseek-v4-flash'. Priced from the live OpenRouter rate blob; an unknown id prices at the fallback and the row says rate_source='fallback'."
    },
    "tokensIn": {
      "type": "integer",
      "minimum": 0,
      "maximum": 10000000,
      "description": "Prompt tokens actually consumed."
    },
    "tokensOut": {
      "type": "integer",
      "minimum": 0,
      "maximum": 10000000,
      "description": "Completion tokens actually consumed, INCLUDING reasoning tokens."
    },
    "reason": {
      "description": "What the call was for. Default agent_run.",
      "type": "string",
      "enum": [
        "agent_run",
        "skill_call",
        "inference"
      ]
    },
    "threadId": {
      "description": "The thread the call served, if any — carried on the credits.spent event.",
      "type": "string",
      "maxLength": 200
    }
  },
  "required": [
    "model",
    "tokensIn",
    "tokensOut"
  ]
}
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "ok": {
      "type": "boolean"
    },
    "credits": {
      "description": "Credits charged (cost + margins).",
      "type": "number"
    },
    "costCredits": {
      "description": "The upstream cost in credits, before margins.",
      "type": "number"
    },
    "recorded": {
      "description": "true on a refusal: the tokens were already spent, so the row is written anyway and the balance goes negative.",
      "type": "boolean"
    },
    "error": {
      "description": "unauthorized | invalid_request | nothing_to_spend | ledger_unavailable | meter_run_failed | 402 | floored | budget_exhausted | float_locked",
      "type": "string"
    }
  },
  "required": [
    "ok"
  ]
}