openclaw-freerouter 1.3.0
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/CHANGELOG.md +26 -0
- package/LICENSE +21 -0
- package/README.md +103 -0
- package/index.ts +63 -0
- package/openclaw.plugin.json +25 -0
- package/package.json +37 -0
- package/src/auth.ts +128 -0
- package/src/config.ts +220 -0
- package/src/logger.ts +32 -0
- package/src/models.ts +142 -0
- package/src/provider.ts +676 -0
- package/src/router/config.ts +242 -0
- package/src/router/index.ts +114 -0
- package/src/router/rules.ts +299 -0
- package/src/router/selector.ts +117 -0
- package/src/router/types.ts +84 -0
- package/src/server.ts +381 -0
package/src/models.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model Definitions — Direct API (No BlockRun/x402)
|
|
3
|
+
*
|
|
4
|
+
* Maps YOUR provider models with pricing for the cost calculator.
|
|
5
|
+
* These match the models configured in your openclaw.json.
|
|
6
|
+
*
|
|
7
|
+
* Pricing is in USD per 1M tokens.
|
|
8
|
+
* Add/remove models as you add providers to openclaw.json.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export type ModelDef = {
|
|
12
|
+
/** OpenClaw model ID: "provider/model-id" */
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
inputPrice: number; // $/1M input tokens
|
|
16
|
+
outputPrice: number; // $/1M output tokens
|
|
17
|
+
contextWindow: number;
|
|
18
|
+
maxOutput: number;
|
|
19
|
+
reasoning?: boolean;
|
|
20
|
+
vision?: boolean;
|
|
21
|
+
agentic?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// ─── YOUR CONFIGURED MODELS ───
|
|
25
|
+
|
|
26
|
+
export const MODELS: ModelDef[] = [
|
|
27
|
+
// ═══ Anthropic (configured, API key active) ═══
|
|
28
|
+
{
|
|
29
|
+
id: "anthropic/claude-opus-4-6",
|
|
30
|
+
name: "Claude Opus 4",
|
|
31
|
+
inputPrice: 15,
|
|
32
|
+
outputPrice: 75,
|
|
33
|
+
contextWindow: 200_000,
|
|
34
|
+
maxOutput: 32_000,
|
|
35
|
+
reasoning: true,
|
|
36
|
+
vision: true,
|
|
37
|
+
agentic: true,
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
// ═══ Kimi/Moonshot (configured, API key active) ═══
|
|
41
|
+
{
|
|
42
|
+
id: "kimi-coding/kimi-for-coding",
|
|
43
|
+
name: "Kimi K2.5",
|
|
44
|
+
inputPrice: 0.5,
|
|
45
|
+
outputPrice: 2.4,
|
|
46
|
+
contextWindow: 262_144,
|
|
47
|
+
maxOutput: 4_096,
|
|
48
|
+
reasoning: true,
|
|
49
|
+
vision: true,
|
|
50
|
+
agentic: true,
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
// ═══ OpenAI (API key available — add to openclaw.json) ═══
|
|
54
|
+
{
|
|
55
|
+
id: "openai/gpt-4o",
|
|
56
|
+
name: "GPT-4o",
|
|
57
|
+
inputPrice: 2.5,
|
|
58
|
+
outputPrice: 10,
|
|
59
|
+
contextWindow: 128_000,
|
|
60
|
+
maxOutput: 16_384,
|
|
61
|
+
vision: true,
|
|
62
|
+
agentic: true,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: "openai/gpt-4o-mini",
|
|
66
|
+
name: "GPT-4o Mini",
|
|
67
|
+
inputPrice: 0.15,
|
|
68
|
+
outputPrice: 0.6,
|
|
69
|
+
contextWindow: 128_000,
|
|
70
|
+
maxOutput: 16_384,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: "openai/o3",
|
|
74
|
+
name: "o3",
|
|
75
|
+
inputPrice: 2.0,
|
|
76
|
+
outputPrice: 8.0,
|
|
77
|
+
contextWindow: 200_000,
|
|
78
|
+
maxOutput: 100_000,
|
|
79
|
+
reasoning: true,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: "openai/o3-mini",
|
|
83
|
+
name: "o3-mini",
|
|
84
|
+
inputPrice: 1.1,
|
|
85
|
+
outputPrice: 4.4,
|
|
86
|
+
contextWindow: 128_000,
|
|
87
|
+
maxOutput: 65_536,
|
|
88
|
+
reasoning: true,
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
// ═══ Google (service account available — add to openclaw.json) ═══
|
|
92
|
+
{
|
|
93
|
+
id: "google/gemini-2.5-pro",
|
|
94
|
+
name: "Gemini 2.5 Pro",
|
|
95
|
+
inputPrice: 1.25,
|
|
96
|
+
outputPrice: 10,
|
|
97
|
+
contextWindow: 1_050_000,
|
|
98
|
+
maxOutput: 65_536,
|
|
99
|
+
reasoning: true,
|
|
100
|
+
vision: true,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: "google/gemini-2.5-flash",
|
|
104
|
+
name: "Gemini 2.5 Flash",
|
|
105
|
+
inputPrice: 0.15,
|
|
106
|
+
outputPrice: 0.6,
|
|
107
|
+
contextWindow: 1_000_000,
|
|
108
|
+
maxOutput: 65_536,
|
|
109
|
+
},
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Build the pricing map used by the router.
|
|
114
|
+
*/
|
|
115
|
+
export function buildPricingMap(): Map<string, { inputPrice: number; outputPrice: number }> {
|
|
116
|
+
const map = new Map<string, { inputPrice: number; outputPrice: number }>();
|
|
117
|
+
for (const m of MODELS) {
|
|
118
|
+
map.set(m.id, { inputPrice: m.inputPrice, outputPrice: m.outputPrice });
|
|
119
|
+
}
|
|
120
|
+
return map;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Get context window for a model ID.
|
|
125
|
+
*/
|
|
126
|
+
export function getContextWindow(modelId: string): number | undefined {
|
|
127
|
+
return MODELS.find((m) => m.id === modelId)?.contextWindow;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Check if a model supports reasoning.
|
|
132
|
+
*/
|
|
133
|
+
export function isReasoningModel(modelId: string): boolean {
|
|
134
|
+
return MODELS.find((m) => m.id === modelId)?.reasoning ?? false;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Check if a model is optimized for agentic workflows.
|
|
139
|
+
*/
|
|
140
|
+
export function isAgenticModel(modelId: string): boolean {
|
|
141
|
+
return MODELS.find((m) => m.id === modelId)?.agentic ?? false;
|
|
142
|
+
}
|