File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -202,6 +202,38 @@ two-party event loops that do not go through the shared inbound reply runner.
202202 </Warning>
203203
204204 </Accordion >
205+
206+ <Accordion title =" api.runtime.usage " >
207+ Resolve configured model pricing and estimate token usage cost without
208+ duplicating OpenClaw pricing tables inside a plugin.
209+
210+ ```typescript
211+ const costConfig = api.runtime.usage.resolveModelCostConfig({
212+ provider: "anthropic",
213+ model: "claude-sonnet-4-6",
214+ });
215+
216+ if (costConfig) {
217+ const estimatedCostUsd = api.runtime.usage.estimateUsageCost({
218+ usage: {
219+ input: 12_000,
220+ output: 2_000,
221+ },
222+ cost: costConfig,
223+ });
224+ }
225+ ```
226+
227+ `resolveModelCostConfig(...)` returns OpenClaw's active pricing config for
228+ the requested provider/model pair when one is available. `estimateUsageCost(...)`
229+ applies that config to token usage and returns the estimated USD cost.
230+
231+ This namespace is intended for local plugin accounting, preflight warnings,
232+ and status/reporting surfaces. It should not be used as a billing authority;
233+ providers remain the source of truth for final charged usage.
234+
235+ </Accordion >
236+
205237 <Accordion title =" api.runtime.subagent " >
206238 Launch and manage background subagent runs.
207239
Original file line number Diff line number Diff line change @@ -273,6 +273,15 @@ describe("plugin runtime command execution", () => {
273273 ] ) ;
274274 } ,
275275 } ,
276+ {
277+ name : "exposes runtime.usage pricing helpers" ,
278+ assert : ( runtime : ReturnType < typeof createPluginRuntime > ) => {
279+ expectFunctionKeys ( runtime . usage as Record < string , unknown > , [
280+ "resolveModelCostConfig" ,
281+ "estimateUsageCost" ,
282+ ] ) ;
283+ } ,
284+ } ,
276285 {
277286 name : "exposes canonical runtime.tasks task runtimes while keeping legacy TaskFlow aliases" ,
278287 assert : ( runtime : ReturnType < typeof createPluginRuntime > ) => {
You can’t perform that action at this time.
0 commit comments