@warlock.js/ai-anthropic 5.30.0 → 5.32.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 +58 -6
- package/cjs/index.cjs +847 -138
- package/cjs/index.cjs.map +1 -1
- package/esm/config.type.d.mts +117 -8
- package/esm/config.type.d.mts.map +1 -1
- package/esm/index.d.mts +9 -3
- package/esm/index.mjs +7 -1
- package/esm/known-output-limits.mjs +46 -0
- package/esm/known-output-limits.mjs.map +1 -0
- package/esm/known-pricing.d.mts +63 -0
- package/esm/known-pricing.d.mts.map +1 -0
- package/esm/known-pricing.mjs +172 -0
- package/esm/known-pricing.mjs.map +1 -0
- package/esm/model.d.mts +90 -20
- package/esm/model.d.mts.map +1 -1
- package/esm/model.mjs +389 -88
- package/esm/model.mjs.map +1 -1
- package/esm/request.type.d.mts +23 -0
- package/esm/request.type.d.mts.map +1 -0
- package/esm/sdk.d.mts +1 -3
- package/esm/sdk.d.mts.map +1 -1
- package/esm/thinking-mode.d.mts +14 -2
- package/esm/thinking-mode.d.mts.map +1 -1
- package/esm/thinking-mode.mjs +102 -2
- package/esm/thinking-mode.mjs.map +1 -1
- package/esm/utils/cache-usage.mjs +62 -0
- package/esm/utils/cache-usage.mjs.map +1 -0
- package/esm/utils/index.d.mts +6 -0
- package/esm/utils/index.mjs +1 -1
- package/esm/utils/map-stop-reason.d.mts +1 -0
- package/esm/utils/provider-blocks.d.mts +37 -0
- package/esm/utils/provider-blocks.d.mts.map +1 -0
- package/esm/utils/provider-blocks.mjs +3 -3
- package/esm/utils/provider-blocks.mjs.map +1 -1
- package/esm/utils/server-tool-usage.mjs +17 -0
- package/esm/utils/server-tool-usage.mjs.map +1 -0
- package/esm/utils/to-anthropic-messages.d.mts +69 -0
- package/esm/utils/to-anthropic-messages.d.mts.map +1 -0
- package/esm/utils/to-anthropic-messages.mjs +12 -4
- package/esm/utils/to-anthropic-messages.mjs.map +1 -1
- package/esm/utils/to-anthropic-tools.d.mts +17 -0
- package/esm/utils/to-anthropic-tools.d.mts.map +1 -0
- package/esm/utils/wrap-anthropic-error.d.mts +1 -0
- package/esm/utils/wrap-anthropic-error.mjs +6 -1
- package/esm/utils/wrap-anthropic-error.mjs.map +1 -1
- package/llms-full.txt +248 -32
- package/llms.txt +1 -1
- package/package.json +3 -3
- package/skills/README.md +1 -1
- package/skills/setup-anthropic/SKILL.md +248 -32
package/esm/config.type.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AnthropicThinkingMode } from "./thinking-mode.mjs";
|
|
2
2
|
import { ClientOptions } from "@anthropic-ai/sdk";
|
|
3
3
|
import { ModelConfig, ModelPricing } from "@warlock.js/ai";
|
|
4
|
-
|
|
5
4
|
//#region ../../packages/ai-anthropic/src/config.type.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* Configuration for the Anthropic SDK adapter.
|
|
@@ -32,7 +31,7 @@ import { ModelConfig, ModelPricing } from "@warlock.js/ai";
|
|
|
32
31
|
* },
|
|
33
32
|
* });
|
|
34
33
|
*/
|
|
35
|
-
type AnthropicSDKConfig = ClientOptions & {
|
|
34
|
+
export type AnthropicSDKConfig = ClientOptions & {
|
|
36
35
|
provider?: string;
|
|
37
36
|
/**
|
|
38
37
|
* Per-model USD pricing registry, keyed by model name. Surfaced onto
|
|
@@ -49,7 +48,7 @@ type AnthropicSDKConfig = ClientOptions & {
|
|
|
49
48
|
* anthropic.model({ name: "claude-sonnet-4-6" }); // vision auto-true
|
|
50
49
|
* anthropic.model({ name: "custom-proxy-model", vision: false }); // dev override
|
|
51
50
|
*/
|
|
52
|
-
type AnthropicModelConfig = ModelConfig & {
|
|
51
|
+
export type AnthropicModelConfig = ModelConfig & {
|
|
53
52
|
/**
|
|
54
53
|
* Override the auto-inferred vision capability. When omitted, the
|
|
55
54
|
* adapter checks the model name against the known Claude vision
|
|
@@ -58,6 +57,18 @@ type AnthropicModelConfig = ModelConfig & {
|
|
|
58
57
|
* deployments or capability-degraded testing.
|
|
59
58
|
*/
|
|
60
59
|
vision?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* The model's maximum output tokens, used to size the default
|
|
62
|
+
* `max_tokens` when no `maxTokens` is set. Inferred from known Claude
|
|
63
|
+
* ids (`known-output-limits.ts`: 128K for the Claude 5 family and
|
|
64
|
+
* Opus 4.6–4.8 / Sonnet 4.6, 64K for Opus / Sonnet / Haiku 4.5); set it
|
|
65
|
+
* for gateway or proxy ids the adapter does not recognise. Unknown ids
|
|
66
|
+
* default to 16384.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* anthropic.model({ name: "my-gateway/opus", maxOutputTokens: 128_000 });
|
|
70
|
+
*/
|
|
71
|
+
maxOutputTokens?: number;
|
|
61
72
|
/**
|
|
62
73
|
* Override the inferred `structuredOutput` capability. When omitted,
|
|
63
74
|
* the adapter treats the model as capable and forwards
|
|
@@ -124,6 +135,79 @@ type AnthropicModelConfig = ModelConfig & {
|
|
|
124
135
|
* anthropic.model({ name: "my-gateway/haiku", thinkingMode: "budget" });
|
|
125
136
|
*/
|
|
126
137
|
thinkingMode?: AnthropicThinkingMode;
|
|
138
|
+
/**
|
|
139
|
+
* Override whether the model runs Anthropic's preserved-thinking
|
|
140
|
+
* conversation check (a replayed thinking block is valid only while
|
|
141
|
+
* everything before it is unchanged). When omitted it is inferred from the
|
|
142
|
+
* model name: `true` for Claude Fable 5.1, Opus 5.5, Sonnet 5.5, Haiku 5.5
|
|
143
|
+
* and unknown ids on adaptive thinking; `false` for older models and every
|
|
144
|
+
* budget-mode model.
|
|
145
|
+
*
|
|
146
|
+
* When `true`, assistant turns that client-side compaction kept after its
|
|
147
|
+
* summary (`Message.compaction === "retained"`) are replayed without their
|
|
148
|
+
* thinking blocks, which were produced against the replaced history.
|
|
149
|
+
*/
|
|
150
|
+
preservedThinking?: boolean;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* `clear_tool_uses_20250919` context editing: the API replaces the oldest
|
|
154
|
+
* tool results with a placeholder once the prompt passes `trigger`. Omitted
|
|
155
|
+
* fields use the API defaults (trigger 100,000 input tokens, keep 3 tool
|
|
156
|
+
* uses; Anthropic docs, "Context editing", read 2026-10-17).
|
|
157
|
+
*/
|
|
158
|
+
export type AnthropicClearToolUses = {
|
|
159
|
+
/** When clearing starts: an input-token count or a tool-use count. */
|
|
160
|
+
trigger?: {
|
|
161
|
+
inputTokens: number;
|
|
162
|
+
} | {
|
|
163
|
+
toolUses: number;
|
|
164
|
+
};
|
|
165
|
+
/** How many of the most recent tool uses keep their results. */
|
|
166
|
+
keep?: number;
|
|
167
|
+
/** Apply only when at least this many input tokens can be cleared. */
|
|
168
|
+
clearAtLeast?: number;
|
|
169
|
+
/** Tool names whose uses and results are never cleared. */
|
|
170
|
+
excludeTools?: string[];
|
|
171
|
+
/** Also clear the tool-use inputs: `true` for every tool, or a list of tool names. */
|
|
172
|
+
clearToolInputs?: boolean | string[];
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* `clear_thinking_20251015` context editing: keep thinking blocks for only
|
|
176
|
+
* the most recent `keep` assistant turns, or `"all"`. Omitted, the
|
|
177
|
+
* model's default applies (keep all on Opus 4.5+, Sonnet 4.6+, Haiku 5.5 and
|
|
178
|
+
* the Fable / Mythos models; last turn only on older ones).
|
|
179
|
+
*/
|
|
180
|
+
export type AnthropicClearThinking = {
|
|
181
|
+
keep?: number | "all";
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Typed Anthropic context editing (beta `context-management-2025-06-27`,
|
|
185
|
+
* added automatically). Server-side edits don't count as history edits for
|
|
186
|
+
* preserved thinking: the API checks the conversation as you sent it.
|
|
187
|
+
*/
|
|
188
|
+
export type AnthropicContextManagement = {
|
|
189
|
+
/** Clear old tool results. `true` uses the API defaults. */
|
|
190
|
+
clearToolUses?: true | AnthropicClearToolUses;
|
|
191
|
+
/** Clear thinking blocks from older turns. `true` uses the model default. */
|
|
192
|
+
clearThinking?: true | AnthropicClearThinking;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Server-side compaction at a token threshold (`compact_20260112`, beta
|
|
196
|
+
* `compact-2026-01-12`, added automatically). When the prompt reaches
|
|
197
|
+
* `triggerTokens` the API summarizes earlier context into a `compaction`
|
|
198
|
+
* block at the start of the response; the agent keeps it on the turn's
|
|
199
|
+
* `blocks` and the next request sends it back, so the API drops what came
|
|
200
|
+
* before it. Source: Anthropic docs, "Compaction at a token threshold",
|
|
201
|
+
* read 2026-10-17.
|
|
202
|
+
*/
|
|
203
|
+
export type AnthropicServerCompaction = {
|
|
204
|
+
/** Input tokens that trigger compaction. At least 50,000; API default 150,000. */
|
|
205
|
+
triggerTokens?: number;
|
|
206
|
+
/**
|
|
207
|
+
* Replaces the default summarization prompt entirely. When the request has
|
|
208
|
+
* tools, say "do not call any tools", or the summary step may call one.
|
|
209
|
+
*/
|
|
210
|
+
instructions?: string;
|
|
127
211
|
};
|
|
128
212
|
/**
|
|
129
213
|
* Anthropic-only request options, passed per call (or through the agent's
|
|
@@ -132,14 +216,14 @@ type AnthropicModelConfig = ModelConfig & {
|
|
|
132
216
|
* fallback chain.
|
|
133
217
|
*
|
|
134
218
|
* @example
|
|
135
|
-
* // Server-side compaction (
|
|
219
|
+
* // Server-side compaction and tool-result clearing (betas added for you).
|
|
136
220
|
* const agent = ai.agent({
|
|
137
221
|
* model: anthropic.model({ name: "claude-opus-5-5" }),
|
|
138
222
|
* modelOptions: {
|
|
139
223
|
* providerOptions: {
|
|
140
224
|
* anthropic: {
|
|
141
|
-
*
|
|
142
|
-
*
|
|
225
|
+
* serverCompaction: { triggerTokens: 200_000 },
|
|
226
|
+
* contextManagement: { clearToolUses: { trigger: { inputTokens: 100_000 }, keep: 5 } },
|
|
143
227
|
* },
|
|
144
228
|
* },
|
|
145
229
|
* },
|
|
@@ -158,7 +242,7 @@ type AnthropicModelConfig = ModelConfig & {
|
|
|
158
242
|
* },
|
|
159
243
|
* });
|
|
160
244
|
*/
|
|
161
|
-
type AnthropicCallOptions = {
|
|
245
|
+
export type AnthropicCallOptions = {
|
|
162
246
|
/**
|
|
163
247
|
* Beta flags (`anthropic-beta` header values). When non-empty the
|
|
164
248
|
* request goes through the SDK's `client.beta.messages` endpoint, which
|
|
@@ -187,7 +271,32 @@ type AnthropicCallOptions = {
|
|
|
187
271
|
* is enough). Ignored on budget-mode models.
|
|
188
272
|
*/
|
|
189
273
|
thinkingDisplay?: "summarized" | "omitted" | "updates";
|
|
274
|
+
/**
|
|
275
|
+
* Typed context editing: clear old tool results and/or old thinking
|
|
276
|
+
* blocks server-side. Adds `context_management.edits` and the
|
|
277
|
+
* `context-management-2025-06-27` beta. Cannot be combined with a
|
|
278
|
+
* `context_management` field in `body`.
|
|
279
|
+
*/
|
|
280
|
+
contextManagement?: AnthropicContextManagement;
|
|
281
|
+
/**
|
|
282
|
+
* Server-side compaction at a token threshold: `true` for the API
|
|
283
|
+
* defaults, or `{ triggerTokens, instructions }`. Adds the
|
|
284
|
+
* `compact_20260112` edit and the `compact-2026-01-12` beta. Cannot be
|
|
285
|
+
* combined with a `context_management` field in `body`.
|
|
286
|
+
*/
|
|
287
|
+
serverCompaction?: boolean | AnthropicServerCompaction;
|
|
288
|
+
/**
|
|
289
|
+
* `thinking.block_binding.prefix_mismatch_behavior` (beta
|
|
290
|
+
* `thinking-binding-controls-2026-08-01`, added automatically): what the
|
|
291
|
+
* API does with a replayed thinking block whose conversation changed —
|
|
292
|
+
* `"error"` (a 400) or `"drop_block"` (drop it and every later one,
|
|
293
|
+
* reported in `input_transformations`). Use `"drop_block"` to recover a
|
|
294
|
+
* stored conversation that was edited. Applied to adaptive and
|
|
295
|
+
* budget-mode thinking; ignored, with a debug log, when the request sends
|
|
296
|
+
* thinking in another shape. While set, retained turns are replayed with
|
|
297
|
+
* their thinking blocks and the API decides.
|
|
298
|
+
*/
|
|
299
|
+
thinkingBlockBinding?: "error" | "drop_block";
|
|
190
300
|
};
|
|
191
301
|
//#endregion
|
|
192
|
-
export { AnthropicCallOptions, AnthropicModelConfig, AnthropicSDKConfig };
|
|
193
302
|
//# sourceMappingURL=config.type.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.type.d.mts","names":[],"sources":["../../../../../../../packages/ai-anthropic/src/config.type.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.type.d.mts","names":[],"sources":["../../../../../../../packages/ai-anthropic/src/config.type.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAiCY,qBAAqB;EAC/B;;;;;;EAMA,UAAU,eAAe;;;;;;;;;;YAWf,uBAAuB;;;;;;;;EAQjC;;;;;;;;;;;;EAYA;;;;;;;;;EASA;;;;;;;;;;;;;;;;;;;;;EAqBA;;;;;;;;EAQA;;;;;;;;;;EAUA;;;;;;;;;;;;;;;;;;EAkBA,eAAe;;;;;;;;;;;;;EAaf;;;;;;;;YASU;;EAEV;IAAY;;IAA0B;;;EAEtC;;EAEA;;EAEA;;EAEA;;;;;;;;YASU;EAA2B;;;;;;;YAO3B;;EAEV,uBAAuB;;EAEvB,uBAAuB;;;;;;;;;;;YAYb;;EAEV;;;;;EAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAoCU;;;;;;;EAOV;;;;;;;;;;EAUA,OAAO;;;;;;;;;;;EAWP;;;;;;;EAOA,oBAAoB;;;;;;;EAOpB,6BAA6B;;;;;;;;;;;;EAY7B"}
|
package/esm/index.d.mts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { AnthropicThinkingMode } from "./thinking-mode.mjs";
|
|
2
|
-
import { AnthropicCallOptions, AnthropicModelConfig, AnthropicSDKConfig } from "./config.type.mjs";
|
|
1
|
+
import { AnthropicThinkingMode, inferPreservedThinking } from "./thinking-mode.mjs";
|
|
2
|
+
import { AnthropicCallOptions, AnthropicClearThinking, AnthropicClearToolUses, AnthropicContextManagement, AnthropicModelConfig, AnthropicSDKConfig, AnthropicServerCompaction } from "./config.type.mjs";
|
|
3
|
+
import { AnthropicNonStreamingRequest, AnthropicRequest, AnthropicRequestOptions, AnthropicStreamingRequest } from "./request.type.mjs";
|
|
3
4
|
import { AnthropicModel } from "./model.mjs";
|
|
4
5
|
import { AnthropicSDK } from "./sdk.mjs";
|
|
5
|
-
|
|
6
|
+
import { ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_PRICING, ANTHROPIC_SERVER_TOOL_PRICING, anthropicPricingFor, withAnthropicCacheWriteRates } from "./known-pricing.mjs";
|
|
7
|
+
import { ANTHROPIC_BLOCK_FORMAT, fromProviderBlocks, toProviderBlocks } from "./utils/provider-blocks.mjs";
|
|
8
|
+
import { AnthropicMessages, ToAnthropicMessagesOptions, toAnthropicMessages } from "./utils/to-anthropic-messages.mjs";
|
|
9
|
+
import { toAnthropicTools } from "./utils/to-anthropic-tools.mjs";
|
|
10
|
+
import "./utils/index.mjs";
|
|
11
|
+
export { ANTHROPIC_BLOCK_FORMAT, ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_PRICING, ANTHROPIC_SERVER_TOOL_PRICING, type AnthropicCallOptions, type AnthropicClearThinking, type AnthropicClearToolUses, type AnthropicContextManagement, type AnthropicMessages, AnthropicModel, type AnthropicModelConfig, type AnthropicNonStreamingRequest, type AnthropicRequest, type AnthropicRequestOptions, AnthropicSDK, type AnthropicSDKConfig, type AnthropicServerCompaction, type AnthropicStreamingRequest, type AnthropicThinkingMode, type ToAnthropicMessagesOptions, anthropicPricingFor, fromProviderBlocks, inferPreservedThinking, toAnthropicMessages, toAnthropicTools, toProviderBlocks, withAnthropicCacheWriteRates };
|
package/esm/index.mjs
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import { ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_PRICING, ANTHROPIC_SERVER_TOOL_PRICING, anthropicPricingFor, withAnthropicCacheWriteRates } from "./known-pricing.mjs";
|
|
2
|
+
import { inferPreservedThinking } from "./thinking-mode.mjs";
|
|
3
|
+
import { ANTHROPIC_BLOCK_FORMAT, fromProviderBlocks, toProviderBlocks } from "./utils/provider-blocks.mjs";
|
|
4
|
+
import { toAnthropicMessages } from "./utils/to-anthropic-messages.mjs";
|
|
5
|
+
import { toAnthropicTools } from "./utils/to-anthropic-tools.mjs";
|
|
6
|
+
import "./utils/index.mjs";
|
|
1
7
|
import { AnthropicModel } from "./model.mjs";
|
|
2
8
|
import { AnthropicSDK } from "./sdk.mjs";
|
|
3
9
|
|
|
4
|
-
export { AnthropicModel, AnthropicSDK };
|
|
10
|
+
export { ANTHROPIC_BLOCK_FORMAT, ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_PRICING, ANTHROPIC_SERVER_TOOL_PRICING, AnthropicModel, AnthropicSDK, anthropicPricingFor, fromProviderBlocks, inferPreservedThinking, toAnthropicMessages, toAnthropicTools, toProviderBlocks, withAnthropicCacheWriteRates };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { matchesReleaseRoot } from "./thinking-mode.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../packages/ai-anthropic/src/known-output-limits.ts
|
|
4
|
+
/** Family prefixes whose every release has a 128K output limit. */
|
|
5
|
+
const FAMILY_128K_PREFIXES = [
|
|
6
|
+
"claude-fable-5",
|
|
7
|
+
"claude-mythos-5",
|
|
8
|
+
"claude-opus-5",
|
|
9
|
+
"claude-sonnet-5",
|
|
10
|
+
"claude-haiku-5"
|
|
11
|
+
];
|
|
12
|
+
/** Individual releases, matched as a release root (dated / `@` variants included). */
|
|
13
|
+
const RELEASE_OUTPUT_LIMITS = [
|
|
14
|
+
["claude-opus-4-8", 128e3],
|
|
15
|
+
["claude-opus-4-7", 128e3],
|
|
16
|
+
["claude-opus-4-6", 128e3],
|
|
17
|
+
["claude-sonnet-4-6", 128e3],
|
|
18
|
+
["claude-opus-4-5", 64e3],
|
|
19
|
+
["claude-sonnet-4-5", 64e3],
|
|
20
|
+
["claude-haiku-4-5", 64e3]
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* The documented maximum output tokens of a Claude model, or `undefined`
|
|
24
|
+
* when the id is not a known Claude model. Platform prefixes before
|
|
25
|
+
* `claude-` (`anthropic.`, `us.anthropic.`) and dated or `@` snapshot
|
|
26
|
+
* suffixes are accepted, so the Bedrock / Google Cloud ids of a known
|
|
27
|
+
* model resolve too. Override per model with
|
|
28
|
+
* `anthropic.model({ name, maxOutputTokens })`.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* inferMaxOutputTokens("claude-opus-5-5"); // → 128000
|
|
32
|
+
* inferMaxOutputTokens("claude-haiku-4-5-20251001"); // → 64000
|
|
33
|
+
* inferMaxOutputTokens("my-gateway/model"); // → undefined
|
|
34
|
+
*/
|
|
35
|
+
function inferMaxOutputTokens(modelName) {
|
|
36
|
+
const lowered = modelName.toLowerCase();
|
|
37
|
+
const start = lowered.indexOf("claude-");
|
|
38
|
+
if (start === -1) return;
|
|
39
|
+
const normalized = lowered.slice(start);
|
|
40
|
+
if (FAMILY_128K_PREFIXES.some((prefix) => normalized.startsWith(prefix))) return 128e3;
|
|
41
|
+
for (const [root, limit] of RELEASE_OUTPUT_LIMITS) if (matchesReleaseRoot(normalized, root)) return limit;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { inferMaxOutputTokens };
|
|
46
|
+
//# sourceMappingURL=known-output-limits.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"known-output-limits.mjs","names":[],"sources":["../../../../../../../packages/ai-anthropic/src/known-output-limits.ts"],"sourcesContent":["import { matchesReleaseRoot } from \"./thinking-mode\";\n\n/*\n * Documented maximum output tokens (`max_tokens`) on the synchronous\n * Messages API. Source: Anthropic's model pages and models overview,\n * platform.claude.com/docs/en/about-claude/models/overview and\n * …/models/{opus-4-5,sonnet-4-5,haiku-4-5}/overview, checked 2026-10-17.\n *\n * | Model ids | Max output |\n * |--------------------------------------------------------------|------------|\n * | Claude 5 family: fable-5 / 5.1, mythos-5 / 5.1, opus-5 / 5.5, | 128K |\n * | sonnet-5 / 5.5, haiku-5-5 | |\n * | claude-opus-4-8, claude-opus-4-7, claude-opus-4-6, | 128K |\n * | claude-sonnet-4-6 | |\n * | claude-opus-4-5, claude-sonnet-4-5, claude-haiku-4-5 | 64K |\n *\n * Older models (Claude 3.x, Opus 4 / 4.1, Sonnet 4) are retired and have no\n * entry; like any id not listed they fall back to the adapter default.\n */\n\n/** Family prefixes whose every release has a 128K output limit. */\nconst FAMILY_128K_PREFIXES = [\n \"claude-fable-5\",\n \"claude-mythos-5\",\n \"claude-opus-5\",\n \"claude-sonnet-5\",\n \"claude-haiku-5\",\n];\n\n/** Individual releases, matched as a release root (dated / `@` variants included). */\nconst RELEASE_OUTPUT_LIMITS: ReadonlyArray<readonly [root: string, limit: number]> = [\n [\"claude-opus-4-8\", 128_000],\n [\"claude-opus-4-7\", 128_000],\n [\"claude-opus-4-6\", 128_000],\n [\"claude-sonnet-4-6\", 128_000],\n [\"claude-opus-4-5\", 64_000],\n [\"claude-sonnet-4-5\", 64_000],\n [\"claude-haiku-4-5\", 64_000],\n];\n\n/**\n * The documented maximum output tokens of a Claude model, or `undefined`\n * when the id is not a known Claude model. Platform prefixes before\n * `claude-` (`anthropic.`, `us.anthropic.`) and dated or `@` snapshot\n * suffixes are accepted, so the Bedrock / Google Cloud ids of a known\n * model resolve too. Override per model with\n * `anthropic.model({ name, maxOutputTokens })`.\n *\n * @example\n * inferMaxOutputTokens(\"claude-opus-5-5\"); // → 128000\n * inferMaxOutputTokens(\"claude-haiku-4-5-20251001\"); // → 64000\n * inferMaxOutputTokens(\"my-gateway/model\"); // → undefined\n */\nexport function inferMaxOutputTokens(modelName: string): number | undefined {\n const lowered = modelName.toLowerCase();\n const start = lowered.indexOf(\"claude-\");\n\n if (start === -1) {\n return undefined;\n }\n\n const normalized = lowered.slice(start);\n\n if (FAMILY_128K_PREFIXES.some((prefix) => normalized.startsWith(prefix))) {\n return 128_000;\n }\n\n for (const [root, limit] of RELEASE_OUTPUT_LIMITS) {\n if (matchesReleaseRoot(normalized, root)) {\n return limit;\n }\n }\n\n return undefined;\n}\n"],"mappings":";;;;AAqBA,MAAM,uBAAuB;CAC3B;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,wBAA+E;CACnF,CAAC,mBAAmB,KAAO;CAC3B,CAAC,mBAAmB,KAAO;CAC3B,CAAC,mBAAmB,KAAO;CAC3B,CAAC,qBAAqB,KAAO;CAC7B,CAAC,mBAAmB,IAAM;CAC1B,CAAC,qBAAqB,IAAM;CAC5B,CAAC,oBAAoB,IAAM;AAC7B;;;;;;;;;;;;;;AAeA,SAAgB,qBAAqB,WAAuC;CAC1E,MAAM,UAAU,UAAU,YAAY;CACtC,MAAM,QAAQ,QAAQ,QAAQ,SAAS;CAEvC,IAAI,UAAU,IACZ;CAGF,MAAM,aAAa,QAAQ,MAAM,KAAK;CAEtC,IAAI,qBAAqB,MAAM,WAAW,WAAW,WAAW,MAAM,CAAC,GACrE,OAAO;CAGT,KAAK,MAAM,CAAC,MAAM,UAAU,uBAC1B,IAAI,mBAAmB,YAAY,IAAI,GACrC,OAAO;AAKb"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ModelPricing } from "@warlock.js/ai";
|
|
2
|
+
//#region ../../packages/ai-anthropic/src/known-pricing.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Anthropic's prompt-cache write multipliers, relative to the base input
|
|
5
|
+
* rate: a 5-minute write costs 1.25x, a 1-hour write 2x. They hold for
|
|
6
|
+
* every Claude model on Anthropic's price list.
|
|
7
|
+
*
|
|
8
|
+
* Source: https://platform.claude.com/docs/en/about-claude/pricing
|
|
9
|
+
* (fetched 2026-10-17).
|
|
10
|
+
*/
|
|
11
|
+
export declare const ANTHROPIC_CACHE_WRITE_MULTIPLIER = 1.25;
|
|
12
|
+
export declare const ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER = 2;
|
|
13
|
+
/**
|
|
14
|
+
* Built-in Claude API list prices, USD per 1,000,000 tokens, keyed by
|
|
15
|
+
* model id. `cachedInput` is the cache-hit rate, `cacheWrite` the
|
|
16
|
+
* 5-minute write rate and `cacheWrite1h` the 1-hour write rate.
|
|
17
|
+
*
|
|
18
|
+
* Source: https://platform.claude.com/docs/en/about-claude/pricing,
|
|
19
|
+
* "Model pricing" table, fetched 2026-10-17. Standard (global) routing,
|
|
20
|
+
* non-batch. Not covered, so pass `pricing` yourself when you need them:
|
|
21
|
+
*
|
|
22
|
+
* - Claude Haiku 5.5 — priced by prompt length (higher rates above
|
|
23
|
+
* 100,000 prompt tokens), which a flat `ModelPricing` cannot express.
|
|
24
|
+
* - US-only inference (`inference_geo: "us"`, 1.1x), fast mode, the Batch
|
|
25
|
+
* API, and Claude on Bedrock / Vertex AI (partner-priced).
|
|
26
|
+
* - Limited-availability models (Mythos) and retired models.
|
|
27
|
+
*
|
|
28
|
+
* Dated snapshot ids (`claude-haiku-4-5-20251001`) resolve to their alias
|
|
29
|
+
* entry through {@link anthropicPricingFor}.
|
|
30
|
+
*/
|
|
31
|
+
export declare const ANTHROPIC_MODEL_PRICING: Readonly<Record<string, ModelPricing>>;
|
|
32
|
+
/**
|
|
33
|
+
* Look up the built-in list price for a Claude model id. Accepts the
|
|
34
|
+
* alias (`claude-sonnet-4-5`) or a dated snapshot
|
|
35
|
+
* (`claude-sonnet-4-5-20250929`). Returns `undefined` for any id not in
|
|
36
|
+
* {@link ANTHROPIC_MODEL_PRICING}, so cost stays unknown rather than wrong.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* anthropicPricingFor("claude-haiku-4-5-20251001"); // { input: 1, output: 5, … }
|
|
40
|
+
* anthropicPricingFor("claude-haiku-5-5"); // undefined (prompt-length tiers)
|
|
41
|
+
*/
|
|
42
|
+
export declare function anthropicPricingFor(modelName: string): ModelPricing | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Fill the cache-write rates Anthropic derives from the input rate
|
|
45
|
+
* (5-minute writes 1.25x, 1-hour writes 2x) into a pricing entry that
|
|
46
|
+
* omits them, so a caller who supplies only `{ input, output }` is no
|
|
47
|
+
* longer billed nothing for cache writes. Explicit rates always win; the
|
|
48
|
+
* cache-read rate is left alone because it differs per model.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* withAnthropicCacheWriteRates({ input: 3, output: 15 });
|
|
52
|
+
* // { input: 3, output: 15, cacheWrite: 3.75, cacheWrite1h: 6 }
|
|
53
|
+
*/
|
|
54
|
+
export declare function withAnthropicCacheWriteRates(pricing: ModelPricing | undefined): ModelPricing | undefined;
|
|
55
|
+
/** USD per request, verified 2026-10-18. Tokens are additional.
|
|
56
|
+
* https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-search-tool#usage-and-pricing
|
|
57
|
+
* https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-fetch-tool#usage-and-pricing */
|
|
58
|
+
export declare const ANTHROPIC_SERVER_TOOL_PRICING: {
|
|
59
|
+
webSearch: number;
|
|
60
|
+
webFetch: number;
|
|
61
|
+
};
|
|
62
|
+
//#endregion
|
|
63
|
+
//# sourceMappingURL=known-pricing.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"known-pricing.d.mts","names":[],"sources":["../../../../../../../packages/ai-anthropic/src/known-pricing.ts"],"mappings":";;;;;;;;;;qBAUa;qBACA;;;;;;;;;;;;;;;;;;;qBAoBA,yBAAyB,SAAS,eAAe;;;;;;;;;;;wBA+C9C,oBAAoB,oBAAoB;;;;;;;;;;;;wBAqBxC,6BACd,SAAS,2BACR;;;;qBAmBU;EAAkC;EAAiB"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
//#region ../../packages/ai-anthropic/src/known-pricing.ts
|
|
2
|
+
/**
|
|
3
|
+
* Anthropic's prompt-cache write multipliers, relative to the base input
|
|
4
|
+
* rate: a 5-minute write costs 1.25x, a 1-hour write 2x. They hold for
|
|
5
|
+
* every Claude model on Anthropic's price list.
|
|
6
|
+
*
|
|
7
|
+
* Source: https://platform.claude.com/docs/en/about-claude/pricing
|
|
8
|
+
* (fetched 2026-10-17).
|
|
9
|
+
*/
|
|
10
|
+
const ANTHROPIC_CACHE_WRITE_MULTIPLIER = 1.25;
|
|
11
|
+
const ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER = 2;
|
|
12
|
+
/**
|
|
13
|
+
* Built-in Claude API list prices, USD per 1,000,000 tokens, keyed by
|
|
14
|
+
* model id. `cachedInput` is the cache-hit rate, `cacheWrite` the
|
|
15
|
+
* 5-minute write rate and `cacheWrite1h` the 1-hour write rate.
|
|
16
|
+
*
|
|
17
|
+
* Source: https://platform.claude.com/docs/en/about-claude/pricing,
|
|
18
|
+
* "Model pricing" table, fetched 2026-10-17. Standard (global) routing,
|
|
19
|
+
* non-batch. Not covered, so pass `pricing` yourself when you need them:
|
|
20
|
+
*
|
|
21
|
+
* - Claude Haiku 5.5 — priced by prompt length (higher rates above
|
|
22
|
+
* 100,000 prompt tokens), which a flat `ModelPricing` cannot express.
|
|
23
|
+
* - US-only inference (`inference_geo: "us"`, 1.1x), fast mode, the Batch
|
|
24
|
+
* API, and Claude on Bedrock / Vertex AI (partner-priced).
|
|
25
|
+
* - Limited-availability models (Mythos) and retired models.
|
|
26
|
+
*
|
|
27
|
+
* Dated snapshot ids (`claude-haiku-4-5-20251001`) resolve to their alias
|
|
28
|
+
* entry through {@link anthropicPricingFor}.
|
|
29
|
+
*/
|
|
30
|
+
const ANTHROPIC_MODEL_PRICING = {
|
|
31
|
+
"claude-fable-5-1": {
|
|
32
|
+
input: 10,
|
|
33
|
+
output: 50,
|
|
34
|
+
cachedInput: .25,
|
|
35
|
+
cacheWrite: 12.5,
|
|
36
|
+
cacheWrite1h: 20
|
|
37
|
+
},
|
|
38
|
+
"claude-fable-5": {
|
|
39
|
+
input: 10,
|
|
40
|
+
output: 50,
|
|
41
|
+
cachedInput: 1,
|
|
42
|
+
cacheWrite: 12.5,
|
|
43
|
+
cacheWrite1h: 20
|
|
44
|
+
},
|
|
45
|
+
"claude-opus-5-5": {
|
|
46
|
+
input: 4,
|
|
47
|
+
output: 20,
|
|
48
|
+
cachedInput: .2,
|
|
49
|
+
cacheWrite: 5,
|
|
50
|
+
cacheWrite1h: 8
|
|
51
|
+
},
|
|
52
|
+
"claude-opus-5": {
|
|
53
|
+
input: 5,
|
|
54
|
+
output: 25,
|
|
55
|
+
cachedInput: .5,
|
|
56
|
+
cacheWrite: 6.25,
|
|
57
|
+
cacheWrite1h: 10
|
|
58
|
+
},
|
|
59
|
+
"claude-opus-4-8": {
|
|
60
|
+
input: 5,
|
|
61
|
+
output: 25,
|
|
62
|
+
cachedInput: .5,
|
|
63
|
+
cacheWrite: 6.25,
|
|
64
|
+
cacheWrite1h: 10
|
|
65
|
+
},
|
|
66
|
+
"claude-opus-4-7": {
|
|
67
|
+
input: 5,
|
|
68
|
+
output: 25,
|
|
69
|
+
cachedInput: .5,
|
|
70
|
+
cacheWrite: 6.25,
|
|
71
|
+
cacheWrite1h: 10
|
|
72
|
+
},
|
|
73
|
+
"claude-opus-4-6": {
|
|
74
|
+
input: 5,
|
|
75
|
+
output: 25,
|
|
76
|
+
cachedInput: .5,
|
|
77
|
+
cacheWrite: 6.25,
|
|
78
|
+
cacheWrite1h: 10
|
|
79
|
+
},
|
|
80
|
+
"claude-opus-4-5": {
|
|
81
|
+
input: 5,
|
|
82
|
+
output: 25,
|
|
83
|
+
cachedInput: .5,
|
|
84
|
+
cacheWrite: 6.25,
|
|
85
|
+
cacheWrite1h: 10
|
|
86
|
+
},
|
|
87
|
+
"claude-sonnet-5-5": {
|
|
88
|
+
input: 2,
|
|
89
|
+
output: 10,
|
|
90
|
+
cachedInput: .1,
|
|
91
|
+
cacheWrite: 2.5,
|
|
92
|
+
cacheWrite1h: 4
|
|
93
|
+
},
|
|
94
|
+
"claude-sonnet-5": {
|
|
95
|
+
input: 2,
|
|
96
|
+
output: 10,
|
|
97
|
+
cachedInput: .2,
|
|
98
|
+
cacheWrite: 2.5,
|
|
99
|
+
cacheWrite1h: 4
|
|
100
|
+
},
|
|
101
|
+
"claude-sonnet-4-6": {
|
|
102
|
+
input: 3,
|
|
103
|
+
output: 15,
|
|
104
|
+
cachedInput: .3,
|
|
105
|
+
cacheWrite: 3.75,
|
|
106
|
+
cacheWrite1h: 6
|
|
107
|
+
},
|
|
108
|
+
"claude-sonnet-4-5": {
|
|
109
|
+
input: 3,
|
|
110
|
+
output: 15,
|
|
111
|
+
cachedInput: .3,
|
|
112
|
+
cacheWrite: 3.75,
|
|
113
|
+
cacheWrite1h: 6
|
|
114
|
+
},
|
|
115
|
+
"claude-haiku-4-5": {
|
|
116
|
+
input: 1,
|
|
117
|
+
output: 5,
|
|
118
|
+
cachedInput: .1,
|
|
119
|
+
cacheWrite: 1.25,
|
|
120
|
+
cacheWrite1h: 2
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
/** A trailing `-YYYYMMDD` snapshot date on a Claude model id. */
|
|
124
|
+
const SNAPSHOT_SUFFIX = /-\d{8}$/;
|
|
125
|
+
/**
|
|
126
|
+
* Look up the built-in list price for a Claude model id. Accepts the
|
|
127
|
+
* alias (`claude-sonnet-4-5`) or a dated snapshot
|
|
128
|
+
* (`claude-sonnet-4-5-20250929`). Returns `undefined` for any id not in
|
|
129
|
+
* {@link ANTHROPIC_MODEL_PRICING}, so cost stays unknown rather than wrong.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* anthropicPricingFor("claude-haiku-4-5-20251001"); // { input: 1, output: 5, … }
|
|
133
|
+
* anthropicPricingFor("claude-haiku-5-5"); // undefined (prompt-length tiers)
|
|
134
|
+
*/
|
|
135
|
+
function anthropicPricingFor(modelName) {
|
|
136
|
+
const exact = ANTHROPIC_MODEL_PRICING[modelName];
|
|
137
|
+
if (exact) return exact;
|
|
138
|
+
return ANTHROPIC_MODEL_PRICING[modelName.replace(SNAPSHOT_SUFFIX, "")];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Fill the cache-write rates Anthropic derives from the input rate
|
|
142
|
+
* (5-minute writes 1.25x, 1-hour writes 2x) into a pricing entry that
|
|
143
|
+
* omits them, so a caller who supplies only `{ input, output }` is no
|
|
144
|
+
* longer billed nothing for cache writes. Explicit rates always win; the
|
|
145
|
+
* cache-read rate is left alone because it differs per model.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* withAnthropicCacheWriteRates({ input: 3, output: 15 });
|
|
149
|
+
* // { input: 3, output: 15, cacheWrite: 3.75, cacheWrite1h: 6 }
|
|
150
|
+
*/
|
|
151
|
+
function withAnthropicCacheWriteRates(pricing) {
|
|
152
|
+
if (!pricing) return;
|
|
153
|
+
const cacheWrite = pricing.cacheWrite ?? pricing.cachedOutput ?? pricing.input * 1.25;
|
|
154
|
+
const cacheWrite1h = pricing.cacheWrite1h ?? pricing.input * 2;
|
|
155
|
+
if (pricing.cacheWrite === cacheWrite && pricing.cacheWrite1h === cacheWrite1h) return pricing;
|
|
156
|
+
return {
|
|
157
|
+
...pricing,
|
|
158
|
+
cacheWrite,
|
|
159
|
+
cacheWrite1h
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/** USD per request, verified 2026-10-18. Tokens are additional.
|
|
163
|
+
* https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-search-tool#usage-and-pricing
|
|
164
|
+
* https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-fetch-tool#usage-and-pricing */
|
|
165
|
+
const ANTHROPIC_SERVER_TOOL_PRICING = {
|
|
166
|
+
webSearch: .01,
|
|
167
|
+
webFetch: 0
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
//#endregion
|
|
171
|
+
export { ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_PRICING, ANTHROPIC_SERVER_TOOL_PRICING, anthropicPricingFor, withAnthropicCacheWriteRates };
|
|
172
|
+
//# sourceMappingURL=known-pricing.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"known-pricing.mjs","names":[],"sources":["../../../../../../../packages/ai-anthropic/src/known-pricing.ts"],"sourcesContent":["import type { ModelPricing } from \"@warlock.js/ai\";\n\n/**\n * Anthropic's prompt-cache write multipliers, relative to the base input\n * rate: a 5-minute write costs 1.25x, a 1-hour write 2x. They hold for\n * every Claude model on Anthropic's price list.\n *\n * Source: https://platform.claude.com/docs/en/about-claude/pricing\n * (fetched 2026-10-17).\n */\nexport const ANTHROPIC_CACHE_WRITE_MULTIPLIER = 1.25;\nexport const ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER = 2;\n\n/**\n * Built-in Claude API list prices, USD per 1,000,000 tokens, keyed by\n * model id. `cachedInput` is the cache-hit rate, `cacheWrite` the\n * 5-minute write rate and `cacheWrite1h` the 1-hour write rate.\n *\n * Source: https://platform.claude.com/docs/en/about-claude/pricing,\n * \"Model pricing\" table, fetched 2026-10-17. Standard (global) routing,\n * non-batch. Not covered, so pass `pricing` yourself when you need them:\n *\n * - Claude Haiku 5.5 — priced by prompt length (higher rates above\n * 100,000 prompt tokens), which a flat `ModelPricing` cannot express.\n * - US-only inference (`inference_geo: \"us\"`, 1.1x), fast mode, the Batch\n * API, and Claude on Bedrock / Vertex AI (partner-priced).\n * - Limited-availability models (Mythos) and retired models.\n *\n * Dated snapshot ids (`claude-haiku-4-5-20251001`) resolve to their alias\n * entry through {@link anthropicPricingFor}.\n */\nexport const ANTHROPIC_MODEL_PRICING: Readonly<Record<string, ModelPricing>> = {\n \"claude-fable-5-1\": {\n input: 10,\n output: 50,\n cachedInput: 0.25,\n cacheWrite: 12.5,\n cacheWrite1h: 20,\n },\n \"claude-fable-5\": { input: 10, output: 50, cachedInput: 1, cacheWrite: 12.5, cacheWrite1h: 20 },\n \"claude-opus-5-5\": { input: 4, output: 20, cachedInput: 0.2, cacheWrite: 5, cacheWrite1h: 8 },\n \"claude-opus-5\": { input: 5, output: 25, cachedInput: 0.5, cacheWrite: 6.25, cacheWrite1h: 10 },\n \"claude-opus-4-8\": { input: 5, output: 25, cachedInput: 0.5, cacheWrite: 6.25, cacheWrite1h: 10 },\n \"claude-opus-4-7\": { input: 5, output: 25, cachedInput: 0.5, cacheWrite: 6.25, cacheWrite1h: 10 },\n \"claude-opus-4-6\": { input: 5, output: 25, cachedInput: 0.5, cacheWrite: 6.25, cacheWrite1h: 10 },\n \"claude-opus-4-5\": { input: 5, output: 25, cachedInput: 0.5, cacheWrite: 6.25, cacheWrite1h: 10 },\n \"claude-sonnet-5-5\": { input: 2, output: 10, cachedInput: 0.1, cacheWrite: 2.5, cacheWrite1h: 4 },\n \"claude-sonnet-5\": { input: 2, output: 10, cachedInput: 0.2, cacheWrite: 2.5, cacheWrite1h: 4 },\n \"claude-sonnet-4-6\": {\n input: 3,\n output: 15,\n cachedInput: 0.3,\n cacheWrite: 3.75,\n cacheWrite1h: 6,\n },\n \"claude-sonnet-4-5\": {\n input: 3,\n output: 15,\n cachedInput: 0.3,\n cacheWrite: 3.75,\n cacheWrite1h: 6,\n },\n \"claude-haiku-4-5\": { input: 1, output: 5, cachedInput: 0.1, cacheWrite: 1.25, cacheWrite1h: 2 },\n};\n\n/** A trailing `-YYYYMMDD` snapshot date on a Claude model id. */\nconst SNAPSHOT_SUFFIX = /-\\d{8}$/;\n\n/**\n * Look up the built-in list price for a Claude model id. Accepts the\n * alias (`claude-sonnet-4-5`) or a dated snapshot\n * (`claude-sonnet-4-5-20250929`). Returns `undefined` for any id not in\n * {@link ANTHROPIC_MODEL_PRICING}, so cost stays unknown rather than wrong.\n *\n * @example\n * anthropicPricingFor(\"claude-haiku-4-5-20251001\"); // { input: 1, output: 5, … }\n * anthropicPricingFor(\"claude-haiku-5-5\"); // undefined (prompt-length tiers)\n */\nexport function anthropicPricingFor(modelName: string): ModelPricing | undefined {\n const exact = ANTHROPIC_MODEL_PRICING[modelName];\n\n if (exact) {\n return exact;\n }\n\n return ANTHROPIC_MODEL_PRICING[modelName.replace(SNAPSHOT_SUFFIX, \"\")];\n}\n\n/**\n * Fill the cache-write rates Anthropic derives from the input rate\n * (5-minute writes 1.25x, 1-hour writes 2x) into a pricing entry that\n * omits them, so a caller who supplies only `{ input, output }` is no\n * longer billed nothing for cache writes. Explicit rates always win; the\n * cache-read rate is left alone because it differs per model.\n *\n * @example\n * withAnthropicCacheWriteRates({ input: 3, output: 15 });\n * // { input: 3, output: 15, cacheWrite: 3.75, cacheWrite1h: 6 }\n */\nexport function withAnthropicCacheWriteRates(\n pricing: ModelPricing | undefined,\n): ModelPricing | undefined {\n if (!pricing) {\n return undefined;\n }\n\n const cacheWrite =\n pricing.cacheWrite ?? pricing.cachedOutput ?? pricing.input * ANTHROPIC_CACHE_WRITE_MULTIPLIER;\n const cacheWrite1h = pricing.cacheWrite1h ?? pricing.input * ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER;\n\n if (pricing.cacheWrite === cacheWrite && pricing.cacheWrite1h === cacheWrite1h) {\n return pricing;\n }\n\n return { ...pricing, cacheWrite, cacheWrite1h };\n}\n\n/** USD per request, verified 2026-10-18. Tokens are additional.\n * https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-search-tool#usage-and-pricing\n * https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-fetch-tool#usage-and-pricing */\nexport const ANTHROPIC_SERVER_TOOL_PRICING = { webSearch: 0.01, webFetch: 0 };\n"],"mappings":";;;;;;;;;AAUA,MAAa,mCAAmC;AAChD,MAAa,sCAAsC;;;;;;;;;;;;;;;;;;;AAoBnD,MAAa,0BAAkE;CAC7E,oBAAoB;EAClB,OAAO;EACP,QAAQ;EACR,aAAa;EACb,YAAY;EACZ,cAAc;CAChB;CACA,kBAAkB;EAAE,OAAO;EAAI,QAAQ;EAAI,aAAa;EAAG,YAAY;EAAM,cAAc;CAAG;CAC9F,mBAAmB;EAAE,OAAO;EAAG,QAAQ;EAAI,aAAa;EAAK,YAAY;EAAG,cAAc;CAAE;CAC5F,iBAAiB;EAAE,OAAO;EAAG,QAAQ;EAAI,aAAa;EAAK,YAAY;EAAM,cAAc;CAAG;CAC9F,mBAAmB;EAAE,OAAO;EAAG,QAAQ;EAAI,aAAa;EAAK,YAAY;EAAM,cAAc;CAAG;CAChG,mBAAmB;EAAE,OAAO;EAAG,QAAQ;EAAI,aAAa;EAAK,YAAY;EAAM,cAAc;CAAG;CAChG,mBAAmB;EAAE,OAAO;EAAG,QAAQ;EAAI,aAAa;EAAK,YAAY;EAAM,cAAc;CAAG;CAChG,mBAAmB;EAAE,OAAO;EAAG,QAAQ;EAAI,aAAa;EAAK,YAAY;EAAM,cAAc;CAAG;CAChG,qBAAqB;EAAE,OAAO;EAAG,QAAQ;EAAI,aAAa;EAAK,YAAY;EAAK,cAAc;CAAE;CAChG,mBAAmB;EAAE,OAAO;EAAG,QAAQ;EAAI,aAAa;EAAK,YAAY;EAAK,cAAc;CAAE;CAC9F,qBAAqB;EACnB,OAAO;EACP,QAAQ;EACR,aAAa;EACb,YAAY;EACZ,cAAc;CAChB;CACA,qBAAqB;EACnB,OAAO;EACP,QAAQ;EACR,aAAa;EACb,YAAY;EACZ,cAAc;CAChB;CACA,oBAAoB;EAAE,OAAO;EAAG,QAAQ;EAAG,aAAa;EAAK,YAAY;EAAM,cAAc;CAAE;AACjG;;AAGA,MAAM,kBAAkB;;;;;;;;;;;AAYxB,SAAgB,oBAAoB,WAA6C;CAC/E,MAAM,QAAQ,wBAAwB;CAEtC,IAAI,OACF,OAAO;CAGT,OAAO,wBAAwB,UAAU,QAAQ,iBAAiB,EAAE;AACtE;;;;;;;;;;;;AAaA,SAAgB,6BACd,SAC0B;CAC1B,IAAI,CAAC,SACH;CAGF,MAAM,aACJ,QAAQ,cAAc,QAAQ,gBAAgB,QAAQ;CACxD,MAAM,eAAe,QAAQ,gBAAgB,QAAQ;CAErD,IAAI,QAAQ,eAAe,cAAc,QAAQ,iBAAiB,cAChE,OAAO;CAGT,OAAO;EAAE,GAAG;EAAS;EAAY;CAAa;AAChD;;;;AAKA,MAAa,gCAAgC;CAAE,WAAW;CAAM,UAAU;AAAE"}
|