Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions build-an-oracle/reference/bundled-plugins/credits.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "credits"
description: "Enforces per-user credit budgets and settles held credits to the chain on a cron."

Check warning on line 3 in build-an-oracle/reference/bundled-plugins/credits.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/bundled-plugins/credits.mdx#L3

Did you really mean 'cron'?
icon: "coins"
---

Expand All @@ -20,7 +20,7 @@
Owns the full credit lifecycle:

- **Enforcement** — per-request middleware that aborts model calls when the user is out of credits (`createCreditsMiddleware` + `TokenLimiter`).
- **Settlement** — background cron that converts held credits into on-chain claims, shipped via `ClaimProcessingModule`.

Check warning on line 23 in build-an-oracle/reference/bundled-plugins/credits.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/bundled-plugins/credits.mdx#L23

Did you really mean 'cron'?

Silent (no agent-visible tools). When loaded, this plugin also activates the runtime's Tier-0 `SubscriptionMiddleware`, which gates the HTTP request before the graph even runs.

Expand All @@ -29,9 +29,10 @@
| Var | Required | Description |
| --- | --- | --- |
| `SUBSCRIPTION_URL` | no | Subscription API URL. |
| `SUBSCRIPTION_ORACLE_MCP_URL` | no | Subscription Agentic Oracles MCP server URL. |

Check warning on line 32 in build-an-oracle/reference/bundled-plugins/credits.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/bundled-plugins/credits.mdx#L32

Did you really mean 'Agentic'?
| `DISABLE_CREDITS` | no | Set to `'true'` to skip the plugin entirely. |
| `MINIMUM_CLAIM_THRESHOLD` | no | Positive integer. Held-credit threshold at or above which the settlement cron submits a user's accumulated credits as an on-chain claim. Defaults to `1000` when unset; invalid values log a warning and fall back to the default. Tune per-oracle to trade off transaction cost against settlement latency. |

Check warning on line 34 in build-an-oracle/reference/bundled-plugins/credits.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/bundled-plugins/credits.mdx#L34

Did you really mean 'cron'?
| `NETWORK` | no | Read but not owned (declared by the core base env schema). Required by the cron module. |

Check warning on line 35 in build-an-oracle/reference/bundled-plugins/credits.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/bundled-plugins/credits.mdx#L35

Did you really mean 'cron'?

## What it contributes

Expand All @@ -39,7 +40,7 @@
- **Sub-agents:** none.
- **Middleware:** `createCreditsMiddleware` (aborts the agent run when the user is out of credits).
- **Nest modules** (when Redis is configured at construct time):
- `ClaimProcessingModule` — cron that settles held credits on chain.

Check warning on line 43 in build-an-oracle/reference/bundled-plugins/credits.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/bundled-plugins/credits.mdx#L43

Did you really mean 'cron'?
- `FileProcessingSinkModule` — `FILE_PROCESSING_CREDIT_SINK` so pre-flight file-processing LLM usage bills the per-user budget.
- `SubscriptionSinkModule` — `SUBSCRIPTION_CREDIT_SINK` so the subscription middleware mirrors per-DID subscription payload + balance into Redis on every authenticated request.
- **HTTP routes:** none directly.
Expand All @@ -61,8 +62,27 @@
});
```

Without a Redis client the middleware loads in pass-through mode and the cron modules are skipped.

Check warning on line 65 in build-an-oracle/reference/bundled-plugins/credits.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/bundled-plugins/credits.mdx#L65

Did you really mean 'cron'?

## Observing claim settlement

The settlement cron emits structured logs under the `[Credits/Claims]` prefix — grep for that tag to trace a claim end-to-end.

Check warning on line 69 in build-an-oracle/reference/bundled-plugins/credits.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/bundled-plugins/credits.mdx#L69

Did you really mean 'cron'?

- **Boot** — one line at startup with the effective settings, e.g. `Claim processing initialized: network=… denom=… minimumClaimThreshold=… disableCredits=… matrixAccountRoomId=set|MISSING`. Use it to confirm the threshold override and required config actually applied.
- **Per tick** — one summary line, `Cron tick: N user(s) at/above threshold T`, then a `user=… heldAmount=… — evaluating` line per candidate, an explicit `SKIP user=… — <reason>` for each user the cron drops (below threshold, no subscription payload in Redis, missing `oracleClaimsCollectionId`, insufficient available credits), and a closing `Cron tick complete: submitted=X skipped=Y failed=Z` counter.

Check warning on line 72 in build-an-oracle/reference/bundled-plugins/credits.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/bundled-plugins/credits.mdx#L72

Did you really mean 'cron'?
- **Per claim** — for every settled claim, the 4-step workflow logs `[step 1/4 submitIntent]` → `[step 2/4 saveToMatrix]` → `[step 3/4 submitToChain]` → `[step 4/4 sendToSubsApi]`, each marked `OK` or `FAILED` and carrying the `intentTxHash`, `claimCid`, and on-chain `chainTxHash` values. A successful claim finishes with `✔ SUBMITTED user=… claimCid=…`. When held credits exceed the oracle's per-claim ceiling, the split is announced with `heldAmount=… exceeds per-claim max … — splitting into N chunks: …`.
- **Pricing source** — before submitting, the cron logs `pricing: fetched on-chain oracle pricing list …` and `cost: claiming heldAmount=… <denom> | per-claim ceiling maxAmount=… <denom>`, so you can confirm the chain-side pricing feeding the split.

Check warning on line 74 in build-an-oracle/reference/bundled-plugins/credits.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/bundled-plugins/credits.mdx#L74

Did you really mean 'cron'?

The credit-charging path (`TokenLimiter.creditsForUsage`) also logs a `source=` marker on every request so you can see which of the three pricing fallbacks priced a call:

| Source | When it fires |
| --- | --- |
| `source=provider-cost` | Provider (e.g. OpenRouter) returned a real USD cost with the response. |
| `source=model-pricing` | Provider cost was missing; per-model input/output pricing was found in cache. |
| `source=flat-rate` | Neither of the above; the flat-rate token-to-credit fallback ran. |

Each line includes `costUsd=$…` and `→ N credits (network=…)`, which makes it easy to spot sub-1-credit charges rounding to `0`.

## Opt out / Opt in

```ts
Expand Down
1 change: 1 addition & 0 deletions build-an-oracle/reference/environment-variables.mdx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: "Environment variables"
description: "Tier-0 (core) vars the runtime always requires, plus per-plugin vars contributed by each bundled plugin's configSchema."

Check warning on line 3 in build-an-oracle/reference/environment-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/environment-variables.mdx#L3

Did you really mean 'configSchema'?
icon: "key"
---

## How env validation works

The runtime composes one big Zod schema at boot: the **Tier-0 base schema** (always required) plus every loaded plugin's **`configSchema`**. `process.env` is validated against the merged schema. Missing required vars fail boot with `[boot-error] Plugin '<name>' env validation failed for '<field>'`.

Check warning on line 9 in build-an-oracle/reference/environment-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/environment-variables.mdx#L9

Did you really mean 'Zod'?

Disabling a plugin (via `features` or `autoDetect`) removes its env requirements automatically.

Expand Down Expand Up @@ -43,7 +43,7 @@
| --- | --- | --- | --- |
| `SQLITE_DATABASE_PATH` | string | — | Required. Must persist across restarts. |

### Blocksync / chain

Check warning on line 46 in build-an-oracle/reference/environment-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/environment-variables.mdx#L46

Did you really mean 'Blocksync'?

| Variable | Type | Default | Notes |
| --- | --- | --- | --- |
Expand Down Expand Up @@ -71,7 +71,7 @@
| `OPEN_ROUTER_API_KEY` | string | — | Required if `LLM_PROVIDER=openrouter`. |
| `NEBIUS_API_KEY` | string | — | Required if `LLM_PROVIDER=nebius`. |

Cross-field check (`validateLlmProviderKey`): the API key for the selected `LLM_PROVIDER` must be present — `OPEN_ROUTER_API_KEY` when `LLM_PROVIDER=openrouter` (the default), `NEBIUS_API_KEY` when `LLM_PROVIDER=nebius`. A missing key fails boot with a named-field error (e.g. `OPEN_ROUTER_API_KEY` / `NEBIUS_API_KEY`) rather than a generic upstream 401 at request time. The per-role model ids are hardcoded per provider — there is no env var to swap the main model id (use the `resolveModel` hook for that).

Check warning on line 74 in build-an-oracle/reference/environment-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/environment-variables.mdx#L74

Did you really mean 'hardcoded'?

### Misc

Expand Down Expand Up @@ -105,7 +105,7 @@
| `composio` | `COMPOSIO_BASE_URL` | No | Defaults to `https://composio.ixo.earth`. |
| `sandbox` | `SANDBOX_MCP_URL` | Yes | Must be a valid URL. |
| `skills` | `SKILLS_CAPSULES_BASE_URL` | No | URL. Defaults to `https://capsules.skills.ixo.earth`. |
| `slack` | `SLACK_BOT_OAUTH_TOKEN` | Yes | Triggers autoDetect. |

Check warning on line 108 in build-an-oracle/reference/environment-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/environment-variables.mdx#L108

Did you really mean 'autoDetect'?
| `slack` | `SLACK_APP_TOKEN` | No | |
| `slack` | `SLACK_USE_SOCKET_MODE` | No | Defaults to `'true'`. |
| `slack` | `SLACK_MAX_RECONNECT_ATTEMPTS` | No | Coerced to number; default `10`. |
Expand All @@ -113,14 +113,15 @@
| `credits` | `SUBSCRIPTION_URL` | No | URL. |
| `credits` | `SUBSCRIPTION_ORACLE_MCP_URL` | No | URL. |
| `credits` | `DISABLE_CREDITS` | No | Enum — exactly `'true'` or `'false'` (any other value fails env validation). `'true'` disables the credit-enforcement middleware; the plugin's `autoDetect` also excludes the whole plugin when `DISABLE_CREDITS=true`. |
| `credits` | `MINIMUM_CLAIM_THRESHOLD` | No | Positive integer (coerced from string). Held-credit threshold at or above which the claim-processing cron settles a user's accumulated credits on-chain. Defaults to `1000` when unset. Invalid values (non-positive, non-numeric) log a warning and fall back to the default. |

Check warning on line 116 in build-an-oracle/reference/environment-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/environment-variables.mdx#L116

Did you really mean 'cron'?
| `tasks` | `REDIS_URL` | Yes (when loaded) | Triggers autoDetect. |

Check warning on line 117 in build-an-oracle/reference/environment-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/environment-variables.mdx#L117

Did you really mean 'autoDetect'?
| `tasks` | `TASKS_MAX_PER_USER` | No | Coerced positive int; default `50`. Max scheduled tasks per user. |
| `tasks` | `TASKS_RUN_LOCK_TTL_SEC` | No | Coerced positive int; default `600`. Per-run lock TTL (seconds). |
| `tasks` | `TASKS_MIN_CRON_INTERVAL_SEC` | No | Coerced positive int; default `300`. Minimum allowed cron interval (seconds). |

Check warning on line 120 in build-an-oracle/reference/environment-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/environment-variables.mdx#L120

Did you really mean 'cron'?
| `matrix-group-chats` | `CHANNEL_MEMORY_SYNC_INTERVAL_MS` | No | Coerced int, min `1000`; default `60000`. Debounce window between a write and the Matrix snapshot upload. |

Check warning on line 121 in build-an-oracle/reference/environment-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/environment-variables.mdx#L121

Did you really mean 'Debounce'?
| `matrix-group-chats` | `GROUP_CHAT_ACTIVE_THREAD_TTL_MS` | No | Coerced int, min `60000`; default `1800000`. How long a thread stays "active with the bot" after a reply. |
| `matrix-group-chats` | `GROUP_CHAT_REQUIRE_POWER_LEVEL` | No | Coerced int, min `0`; default `0`. Extra minimum power level the bot must have before posting (`0` = use the room default). |
| `matrix-group-chats` | `GROUP_CHAT_ROOM_INFO_TTL_MS` | No | Coerced int, min `60000`; default `1800000`. How long roomInfo (membership, DM flag) stays cached. |

Check warning on line 124 in build-an-oracle/reference/environment-variables.mdx

View check run for this annotation

Mintlify / Mintlify Validation (ixoworld) - vale-spellcheck

build-an-oracle/reference/environment-variables.mdx#L124

Did you really mean 'roomInfo'?
| `vfs` | `VFS_MAX_READ_LINES` | No | Coerced positive int; default `2000`. Max lines a single `vfs_read` window returns. |
| `vfs` | `VFS_REQUEST_TIMEOUT_MS` | No | Coerced positive int; default `20000`. Per-request timeout to the VFS worker. |

Expand Down
Loading