clawmoney 0.10.16 → 0.10.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/relay/executor.js +4 -1
- package/dist/relay/pricing.d.ts +20 -0
- package/dist/relay/pricing.js +45 -0
- package/dist/relay/provider.js +9 -17
- package/package.json +1 -1
package/dist/relay/executor.js
CHANGED
|
@@ -106,7 +106,10 @@ export function parseClaudeOutput(raw) {
|
|
|
106
106
|
if (modelUsage) {
|
|
107
107
|
for (const [modelName, usage] of Object.entries(modelUsage)) {
|
|
108
108
|
model = modelName;
|
|
109
|
-
|
|
109
|
+
// Total input = base + cache_creation + cache_read
|
|
110
|
+
inputTokens += (usage.inputTokens ?? 0)
|
|
111
|
+
+ (usage.cacheCreationInputTokens ?? 0)
|
|
112
|
+
+ (usage.cacheReadInputTokens ?? 0);
|
|
110
113
|
outputTokens += usage.outputTokens ?? 0;
|
|
111
114
|
cachedTokens += usage.cacheReadInputTokens ?? 0;
|
|
112
115
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API pricing per million tokens (USD).
|
|
3
|
+
* Source: Official pricing pages (April 2026)
|
|
4
|
+
* - Anthropic: https://platform.claude.com/docs/en/docs/about-claude/pricing
|
|
5
|
+
* - OpenAI: https://developers.openai.com/api/docs/pricing
|
|
6
|
+
* - Google: https://ai.google.dev/gemini-api/docs/pricing
|
|
7
|
+
*/
|
|
8
|
+
export interface ModelPricing {
|
|
9
|
+
input: number;
|
|
10
|
+
output: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const API_PRICES: Record<string, ModelPricing>;
|
|
13
|
+
export declare const RELAY_DISCOUNT = 0.3;
|
|
14
|
+
export declare const PLATFORM_FEE = 0.05;
|
|
15
|
+
export declare function getModelPricing(model: string): ModelPricing;
|
|
16
|
+
export declare function calculateCost(model: string, inputTokens: number, outputTokens: number): {
|
|
17
|
+
apiCost: number;
|
|
18
|
+
relayCost: number;
|
|
19
|
+
providerEarn: number;
|
|
20
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API pricing per million tokens (USD).
|
|
3
|
+
* Source: Official pricing pages (April 2026)
|
|
4
|
+
* - Anthropic: https://platform.claude.com/docs/en/docs/about-claude/pricing
|
|
5
|
+
* - OpenAI: https://developers.openai.com/api/docs/pricing
|
|
6
|
+
* - Google: https://ai.google.dev/gemini-api/docs/pricing
|
|
7
|
+
*/
|
|
8
|
+
export const API_PRICES = {
|
|
9
|
+
// ── Anthropic (Claude) ──
|
|
10
|
+
"claude-opus-4-6": { input: 5, output: 25 },
|
|
11
|
+
"claude-opus-4-5": { input: 5, output: 25 },
|
|
12
|
+
"claude-sonnet-4-6": { input: 3, output: 15 },
|
|
13
|
+
"claude-sonnet-4-5": { input: 3, output: 15 },
|
|
14
|
+
"claude-haiku-4-5": { input: 1, output: 5 },
|
|
15
|
+
// ── OpenAI ──
|
|
16
|
+
"gpt-5.4": { input: 2.50, output: 15 },
|
|
17
|
+
"gpt-5.4-mini": { input: 0.75, output: 4.50 },
|
|
18
|
+
"gpt-5.4-nano": { input: 0.20, output: 1.25 },
|
|
19
|
+
"gpt-5.4-pro": { input: 30, output: 180 },
|
|
20
|
+
"gpt-5.3-codex": { input: 1.75, output: 14 },
|
|
21
|
+
"o3": { input: 5, output: 20 },
|
|
22
|
+
"o4-mini": { input: 4, output: 16 },
|
|
23
|
+
// ── Google (Gemini) ──
|
|
24
|
+
"gemini-2.5-pro": { input: 1.25, output: 10 },
|
|
25
|
+
"gemini-2.5-flash": { input: 0.30, output: 2.50 },
|
|
26
|
+
"gemini-2.5-flash-lite": { input: 0.10, output: 0.40 },
|
|
27
|
+
"gemini-3-flash-preview": { input: 0.50, output: 3 },
|
|
28
|
+
"gemini-3.1-pro-preview": { input: 2, output: 12 },
|
|
29
|
+
};
|
|
30
|
+
// Default fallback for unknown models
|
|
31
|
+
const DEFAULT_PRICING = { input: 5, output: 25 };
|
|
32
|
+
// Relay discount: consumers pay this fraction of API price
|
|
33
|
+
export const RELAY_DISCOUNT = 0.30; // 30% of API price
|
|
34
|
+
// Platform fee: this fraction goes to the platform
|
|
35
|
+
export const PLATFORM_FEE = 0.05; // 5%
|
|
36
|
+
export function getModelPricing(model) {
|
|
37
|
+
return API_PRICES[model] ?? DEFAULT_PRICING;
|
|
38
|
+
}
|
|
39
|
+
export function calculateCost(model, inputTokens, outputTokens) {
|
|
40
|
+
const p = getModelPricing(model);
|
|
41
|
+
const apiCost = (inputTokens * p.input + outputTokens * p.output) / 1_000_000;
|
|
42
|
+
const relayCost = apiCost * RELAY_DISCOUNT;
|
|
43
|
+
const providerEarn = relayCost * (1 - PLATFORM_FEE);
|
|
44
|
+
return { apiCost, relayCost, providerEarn };
|
|
45
|
+
}
|
package/dist/relay/provider.js
CHANGED
|
@@ -4,6 +4,7 @@ import { homedir } from "node:os";
|
|
|
4
4
|
import YAML from "yaml";
|
|
5
5
|
import { RelayWsClient } from "./ws-client.js";
|
|
6
6
|
import { spawnCli, buildCliArgs, parseCliOutput } from "./executor.js";
|
|
7
|
+
import { calculateCost } from "./pricing.js";
|
|
7
8
|
import { relayLogger as logger } from "./logger.js";
|
|
8
9
|
const CONFIG_DIR = join(homedir(), ".clawmoney");
|
|
9
10
|
const CONFIG_FILE = join(CONFIG_DIR, "config.yaml");
|
|
@@ -112,30 +113,21 @@ async function executeRelayRequest(request, config) {
|
|
|
112
113
|
logger.info(` │ Prompt: ${String(lastUserMsg).slice(0, 80)}`);
|
|
113
114
|
try {
|
|
114
115
|
// No session_id — each request is stateless, full history in prompt
|
|
116
|
+
const startMs = Date.now();
|
|
115
117
|
const args = buildCliArgs(cliType, prompt, undefined, max_budget_usd, model);
|
|
116
118
|
const raw = await spawnCli(cliType, args);
|
|
119
|
+
const elapsedMs = Date.now() - startMs;
|
|
117
120
|
const parsed = parseCliOutput(cliType, raw);
|
|
118
121
|
const answer = parsed.text.replace(/\n/g, " ").slice(0, 80);
|
|
119
122
|
const inT = parsed.usage.input_tokens;
|
|
120
123
|
const outT = parsed.usage.output_tokens;
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
"claude-sonnet-4-6": [3, 15],
|
|
125
|
-
"claude-haiku-4-5": [0.8, 4],
|
|
126
|
-
"gpt-5": [10, 30],
|
|
127
|
-
"gpt-5.4": [10, 30],
|
|
128
|
-
"o3": [10, 40],
|
|
129
|
-
"gemini-2.5-pro": [1.25, 10],
|
|
130
|
-
"gemini-2.5-flash": [0.15, 0.6],
|
|
131
|
-
};
|
|
132
|
-
const [apiIn, apiOut] = apiPrices[model] ?? [5, 25];
|
|
133
|
-
const apiCost = (inT * apiIn + outT * apiOut) / 1_000_000;
|
|
134
|
-
const relayCost = apiCost * 0.3; // 30% of API price
|
|
135
|
-
const providerEarn = relayCost * 0.95; // 95% to provider
|
|
124
|
+
const cachedT = parsed.usage.cached_tokens ?? 0;
|
|
125
|
+
const { apiCost, relayCost, providerEarn } = calculateCost(model, inT, outT);
|
|
126
|
+
const elapsedSec = (elapsedMs / 1000).toFixed(1);
|
|
136
127
|
logger.info(` │ Answer: ${answer}`);
|
|
137
|
-
logger.info(` │ Tokens: ${inT} in / ${outT} out`);
|
|
138
|
-
logger.info(` │
|
|
128
|
+
logger.info(` │ Tokens: ${inT} in (${cachedT} cached) / ${outT} out`);
|
|
129
|
+
logger.info(` │ Time: ${elapsedSec}s`);
|
|
130
|
+
logger.info(` │ Cost: API $${apiCost.toFixed(4)} → Relay $${relayCost.toFixed(4)} → Earn $${providerEarn.toFixed(4)}`);
|
|
139
131
|
logger.info(` └─ Done`);
|
|
140
132
|
return {
|
|
141
133
|
event: "relay_response",
|