@warlock.js/ai-anthropic 5.29.0 → 5.31.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 +63 -0
- package/cjs/index.cjs +1124 -147
- package/cjs/index.cjs.map +1 -1
- package/esm/config.type.d.mts +170 -3
- package/esm/config.type.d.mts.map +1 -1
- package/esm/index.d.mts +9 -3
- package/esm/index.mjs +8 -1
- package/esm/known-output-limits.mjs +46 -0
- package/esm/known-output-limits.mjs.map +1 -0
- package/esm/known-pricing.d.mts +58 -0
- package/esm/known-pricing.d.mts.map +1 -0
- package/esm/known-pricing.mjs +165 -0
- package/esm/known-pricing.mjs.map +1 -0
- package/esm/known-vision-models.mjs +1 -1
- package/esm/known-vision-models.mjs.map +1 -1
- package/esm/model.d.mts +322 -0
- package/esm/model.d.mts.map +1 -0
- package/esm/model.mjs +523 -73
- package/esm/model.mjs.map +1 -1
- package/esm/request.type.d.mts +25 -0
- package/esm/request.type.d.mts.map +1 -0
- package/esm/sdk.d.mts +7 -6
- package/esm/sdk.d.mts.map +1 -1
- package/esm/sdk.mjs +4 -4
- package/esm/sdk.mjs.map +1 -1
- package/esm/thinking-mode.d.mts +15 -2
- package/esm/thinking-mode.d.mts.map +1 -1
- package/esm/thinking-mode.mjs +128 -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 +3 -0
- package/esm/utils/index.mjs +1 -0
- package/esm/utils/map-stop-reason.d.mts +1 -0
- package/esm/utils/map-stop-reason.mjs +17 -13
- package/esm/utils/map-stop-reason.mjs.map +1 -1
- package/esm/utils/provider-blocks.d.mts +39 -0
- package/esm/utils/provider-blocks.d.mts.map +1 -0
- package/esm/utils/provider-blocks.mjs +83 -0
- package/esm/utils/provider-blocks.mjs.map +1 -0
- package/esm/utils/to-anthropic-messages.d.mts +71 -0
- package/esm/utils/to-anthropic-messages.d.mts.map +1 -0
- package/esm/utils/to-anthropic-messages.mjs +53 -13
- package/esm/utils/to-anthropic-messages.mjs.map +1 -1
- package/esm/utils/to-anthropic-tools.d.mts +19 -0
- package/esm/utils/to-anthropic-tools.d.mts.map +1 -0
- package/esm/utils/to-anthropic-tools.mjs +1 -1
- package/esm/utils/to-anthropic-tools.mjs.map +1 -1
- package/esm/utils/wrap-anthropic-error.d.mts +1 -0
- package/esm/utils/wrap-anthropic-error.mjs +7 -2
- package/esm/utils/wrap-anthropic-error.mjs.map +1 -1
- package/llms-full.txt +273 -27
- package/llms.txt +1 -1
- package/package.json +5 -4
- package/skills/README.md +1 -1
- package/skills/setup-anthropic/SKILL.md +273 -27
package/esm/config.type.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import { AnthropicThinkingMode } from "./thinking-mode.mjs";
|
|
|
2
2
|
import { ClientOptions } from "@anthropic-ai/sdk";
|
|
3
3
|
import { ModelConfig, ModelPricing } from "@warlock.js/ai";
|
|
4
4
|
|
|
5
|
-
//#region
|
|
5
|
+
//#region ../../packages/ai-anthropic/src/config.type.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* Configuration for the Anthropic SDK adapter.
|
|
8
8
|
*
|
|
@@ -58,6 +58,18 @@ type AnthropicModelConfig = ModelConfig & {
|
|
|
58
58
|
* deployments or capability-degraded testing.
|
|
59
59
|
*/
|
|
60
60
|
vision?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* The model's maximum output tokens, used to size the default
|
|
63
|
+
* `max_tokens` when no `maxTokens` is set. Inferred from known Claude
|
|
64
|
+
* ids (`known-output-limits.ts`: 128K for the Claude 5 family and
|
|
65
|
+
* Opus 4.6–4.8 / Sonnet 4.6, 64K for Opus / Sonnet / Haiku 4.5); set it
|
|
66
|
+
* for gateway or proxy ids the adapter does not recognise. Unknown ids
|
|
67
|
+
* default to 16384.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* anthropic.model({ name: "my-gateway/opus", maxOutputTokens: 128_000 });
|
|
71
|
+
*/
|
|
72
|
+
maxOutputTokens?: number;
|
|
61
73
|
/**
|
|
62
74
|
* Override the inferred `structuredOutput` capability. When omitted,
|
|
63
75
|
* the adapter treats the model as capable and forwards
|
|
@@ -92,7 +104,8 @@ type AnthropicModelConfig = ModelConfig & {
|
|
|
92
104
|
* Lifetime for prompt-cache entries emitted by `promptCaching` and
|
|
93
105
|
* explicit `cacheControl.breakpoints`. Omit for Anthropic's default
|
|
94
106
|
* five-minute TTL; use `"1h"` only when its higher write cost is worth
|
|
95
|
-
* retaining a stable prefix for longer.
|
|
107
|
+
* retaining a stable prefix for longer. A per-call
|
|
108
|
+
* `ModelCallOptions.cacheControl.ttl` overrides it for that call.
|
|
96
109
|
*/
|
|
97
110
|
promptCacheTtl?: "5m" | "1h";
|
|
98
111
|
/**
|
|
@@ -123,7 +136,161 @@ type AnthropicModelConfig = ModelConfig & {
|
|
|
123
136
|
* anthropic.model({ name: "my-gateway/haiku", thinkingMode: "budget" });
|
|
124
137
|
*/
|
|
125
138
|
thinkingMode?: AnthropicThinkingMode;
|
|
139
|
+
/**
|
|
140
|
+
* Override whether the model runs Anthropic's preserved-thinking
|
|
141
|
+
* conversation check (a replayed thinking block is valid only while
|
|
142
|
+
* everything before it is unchanged). When omitted it is inferred from the
|
|
143
|
+
* model name: `true` for Claude Fable 5.1, Opus 5.5, Sonnet 5.5, Haiku 5.5
|
|
144
|
+
* and unknown ids on adaptive thinking; `false` for older models and every
|
|
145
|
+
* budget-mode model.
|
|
146
|
+
*
|
|
147
|
+
* When `true`, assistant turns that client-side compaction kept after its
|
|
148
|
+
* summary (`Message.compaction === "retained"`) are replayed without their
|
|
149
|
+
* thinking blocks, which were produced against the replaced history.
|
|
150
|
+
*/
|
|
151
|
+
preservedThinking?: boolean;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* `clear_tool_uses_20250919` context editing: the API replaces the oldest
|
|
155
|
+
* tool results with a placeholder once the prompt passes `trigger`. Omitted
|
|
156
|
+
* fields use the API defaults (trigger 100,000 input tokens, keep 3 tool
|
|
157
|
+
* uses; Anthropic docs, "Context editing", read 2026-10-17).
|
|
158
|
+
*/
|
|
159
|
+
type AnthropicClearToolUses = {
|
|
160
|
+
/** When clearing starts: an input-token count or a tool-use count. */trigger?: {
|
|
161
|
+
inputTokens: number;
|
|
162
|
+
} | {
|
|
163
|
+
toolUses: number;
|
|
164
|
+
}; /** How many of the most recent tool uses keep their results. */
|
|
165
|
+
keep?: number; /** Apply only when at least this many input tokens can be cleared. */
|
|
166
|
+
clearAtLeast?: number; /** Tool names whose uses and results are never cleared. */
|
|
167
|
+
excludeTools?: string[]; /** Also clear the tool-use inputs: `true` for every tool, or a list of tool names. */
|
|
168
|
+
clearToolInputs?: boolean | string[];
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* `clear_thinking_20251015` context editing: keep thinking blocks for only
|
|
172
|
+
* the most recent `keep` assistant turns, or `"all"`. Omitted, the
|
|
173
|
+
* model's default applies (keep all on Opus 4.5+, Sonnet 4.6+, Haiku 5.5 and
|
|
174
|
+
* the Fable / Mythos models; last turn only on older ones).
|
|
175
|
+
*/
|
|
176
|
+
type AnthropicClearThinking = {
|
|
177
|
+
keep?: number | "all";
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Typed Anthropic context editing (beta `context-management-2025-06-27`,
|
|
181
|
+
* added automatically). Server-side edits don't count as history edits for
|
|
182
|
+
* preserved thinking: the API checks the conversation as you sent it.
|
|
183
|
+
*/
|
|
184
|
+
type AnthropicContextManagement = {
|
|
185
|
+
/** Clear old tool results. `true` uses the API defaults. */clearToolUses?: true | AnthropicClearToolUses; /** Clear thinking blocks from older turns. `true` uses the model default. */
|
|
186
|
+
clearThinking?: true | AnthropicClearThinking;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Server-side compaction at a token threshold (`compact_20260112`, beta
|
|
190
|
+
* `compact-2026-01-12`, added automatically). When the prompt reaches
|
|
191
|
+
* `triggerTokens` the API summarizes earlier context into a `compaction`
|
|
192
|
+
* block at the start of the response; the agent keeps it on the turn's
|
|
193
|
+
* `blocks` and the next request sends it back, so the API drops what came
|
|
194
|
+
* before it. Source: Anthropic docs, "Compaction at a token threshold",
|
|
195
|
+
* read 2026-10-17.
|
|
196
|
+
*/
|
|
197
|
+
type AnthropicServerCompaction = {
|
|
198
|
+
/** Input tokens that trigger compaction. At least 50,000; API default 150,000. */triggerTokens?: number;
|
|
199
|
+
/**
|
|
200
|
+
* Replaces the default summarization prompt entirely. When the request has
|
|
201
|
+
* tools, say "do not call any tools", or the summary step may call one.
|
|
202
|
+
*/
|
|
203
|
+
instructions?: string;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Anthropic-only request options, passed per call (or through the agent's
|
|
207
|
+
* `modelOptions`) as `providerOptions.anthropic`. Other adapters ignore
|
|
208
|
+
* this key, so the same options object is safe in a cross-provider
|
|
209
|
+
* fallback chain.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* // Server-side compaction and tool-result clearing (betas added for you).
|
|
213
|
+
* const agent = ai.agent({
|
|
214
|
+
* model: anthropic.model({ name: "claude-opus-5-5" }),
|
|
215
|
+
* modelOptions: {
|
|
216
|
+
* providerOptions: {
|
|
217
|
+
* anthropic: {
|
|
218
|
+
* serverCompaction: { triggerTokens: 200_000 },
|
|
219
|
+
* contextManagement: { clearToolUses: { trigger: { inputTokens: 100_000 }, keep: 5 } },
|
|
220
|
+
* },
|
|
221
|
+
* },
|
|
222
|
+
* },
|
|
223
|
+
* });
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* // Readable thinking summaries plus the refusal fallback.
|
|
227
|
+
* await model.complete(messages, {
|
|
228
|
+
* reasoning: { effort: "high" },
|
|
229
|
+
* providerOptions: {
|
|
230
|
+
* anthropic: {
|
|
231
|
+
* thinkingDisplay: "summarized",
|
|
232
|
+
* betas: ["server-side-fallback-2026-07-01"],
|
|
233
|
+
* body: { fallbacks: "default" },
|
|
234
|
+
* },
|
|
235
|
+
* },
|
|
236
|
+
* });
|
|
237
|
+
*/
|
|
238
|
+
type AnthropicCallOptions = {
|
|
239
|
+
/**
|
|
240
|
+
* Beta flags (`anthropic-beta` header values). When non-empty the
|
|
241
|
+
* request goes through the SDK's `client.beta.messages` endpoint, which
|
|
242
|
+
* accepts the beta-only body fields (`context_management`, `fallbacks`,
|
|
243
|
+
* `speed`, …) and returns beta-only blocks such as `compaction`.
|
|
244
|
+
*/
|
|
245
|
+
betas?: string[];
|
|
246
|
+
/**
|
|
247
|
+
* Extra Messages API body fields, merged last over the adapter-built
|
|
248
|
+
* body — e.g. `context_management`, `fallbacks`, `inference_geo`,
|
|
249
|
+
* `tool_choice`, `metadata`. Sent as-is: the adapter does not validate
|
|
250
|
+
* them, so a field the endpoint or model rejects surfaces as the
|
|
251
|
+
* provider's 400. The fields the adapter builds from the call —
|
|
252
|
+
* `model`, `messages`, `system`, `tools`, `mcp_servers`, `stream` — are
|
|
253
|
+
* refused with `InvalidRequestError`. Never pass end-user input here.
|
|
254
|
+
*/
|
|
255
|
+
body?: Record<string, unknown>;
|
|
256
|
+
/**
|
|
257
|
+
* `thinking.display` for adaptive-thinking models: `"summarized"`
|
|
258
|
+
* returns readable thinking summaries, `"omitted"` (the API default on
|
|
259
|
+
* Claude 5-family models) returns empty thinking text, `"updates"`
|
|
260
|
+
* returns between-tool progress notes (needs the
|
|
261
|
+
* `thinking-display-updates-2026-08-18` beta). Applied whenever the
|
|
262
|
+
* adapter sends `thinking` to an adaptive-mode model — i.e. alongside a
|
|
263
|
+
* `reasoning` option (on Claude 5-family models, `reasoning: { effort }`
|
|
264
|
+
* is enough). Ignored on budget-mode models.
|
|
265
|
+
*/
|
|
266
|
+
thinkingDisplay?: "summarized" | "omitted" | "updates";
|
|
267
|
+
/**
|
|
268
|
+
* Typed context editing: clear old tool results and/or old thinking
|
|
269
|
+
* blocks server-side. Adds `context_management.edits` and the
|
|
270
|
+
* `context-management-2025-06-27` beta. Cannot be combined with a
|
|
271
|
+
* `context_management` field in `body`.
|
|
272
|
+
*/
|
|
273
|
+
contextManagement?: AnthropicContextManagement;
|
|
274
|
+
/**
|
|
275
|
+
* Server-side compaction at a token threshold: `true` for the API
|
|
276
|
+
* defaults, or `{ triggerTokens, instructions }`. Adds the
|
|
277
|
+
* `compact_20260112` edit and the `compact-2026-01-12` beta. Cannot be
|
|
278
|
+
* combined with a `context_management` field in `body`.
|
|
279
|
+
*/
|
|
280
|
+
serverCompaction?: boolean | AnthropicServerCompaction;
|
|
281
|
+
/**
|
|
282
|
+
* `thinking.block_binding.prefix_mismatch_behavior` (beta
|
|
283
|
+
* `thinking-binding-controls-2026-08-01`, added automatically): what the
|
|
284
|
+
* API does with a replayed thinking block whose conversation changed —
|
|
285
|
+
* `"error"` (a 400) or `"drop_block"` (drop it and every later one,
|
|
286
|
+
* reported in `input_transformations`). Use `"drop_block"` to recover a
|
|
287
|
+
* stored conversation that was edited. Applied to adaptive and
|
|
288
|
+
* budget-mode thinking; ignored, with a debug log, when the request sends
|
|
289
|
+
* thinking in another shape. While set, retained turns are replayed with
|
|
290
|
+
* their thinking blocks and the API decides.
|
|
291
|
+
*/
|
|
292
|
+
thinkingBlockBinding?: "error" | "drop_block";
|
|
126
293
|
};
|
|
127
294
|
//#endregion
|
|
128
|
-
export { AnthropicModelConfig, AnthropicSDKConfig };
|
|
295
|
+
export { AnthropicCallOptions, AnthropicClearThinking, AnthropicClearToolUses, AnthropicContextManagement, AnthropicModelConfig, AnthropicSDKConfig, AnthropicServerCompaction };
|
|
129
296
|
//# sourceMappingURL=config.type.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.type.d.mts","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"config.type.d.mts","names":[],"sources":["../../../../../../../packages/ai-anthropic/src/config.type.ts"],"mappings":";;;;;;;AAiCA;;;;;;;;;;;;;;AAOuC;AAWvC;;;;;;;;;;;;KAlBY,kBAAA,GAAqB,aAAA;EAC/B,QAAA;EAoHiB;AAAA;AASnB;;;EAvHE,OAAA,GAAU,MAAA,SAAe,YAAA;AAAA;;;;;;;;AAiIV;KAtHL,oBAAA,GAAuB,WAAA;EA+HD;;;AAAS;AAO3C;;;EA9HE,MAAA;EAgIA;;;;;AAE6C;AAY/C;;;;AAOc;EAzIZ,eAAA;EA6K8B;;;;;;;;EApK9B,gBAAA;EAqLO;;;;;;;;AAqCa;;;;;;;;;;;;EArMpB,aAAA;;;;;;;;EAQA,cAAA;;;;;;;;;;EAUA,SAAA;;;;;;;;;;;;;;;;;;EAkBA,YAAA,GAAe,qBAAqB;;;;;;;;;;;;;EAapC,iBAAA;AAAA;;;;;;;KASU,sBAAA;wEAEV,OAAA;IAAY,WAAA;EAAA;IAA0B,QAAA;EAAA;EAEtC,IAAA;EAEA,YAAA;EAEA,YAAA;EAEA,eAAA;AAAA;;;;;;;KASU,sBAAA;EAA2B,IAAI;AAAA;;;;;;KAO/B,0BAAA;8DAEV,aAAA,UAAuB,sBAAA;EAEvB,aAAA,UAAuB,sBAAsB;AAAA;;;;;;;;;;KAYnC,yBAAA;oFAEV,aAAA;;;;;EAKA,YAAY;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoCF,oBAAA;;;;;;;EAOV,KAAA;;;;;;;;;;EAUA,IAAA,GAAO,MAAA;;;;;;;;;;;EAWP,eAAA;;;;;;;EAOA,iBAAA,GAAoB,0BAAA;;;;;;;EAOpB,gBAAA,aAA6B,yBAAA;;;;;;;;;;;;EAY7B,oBAAA;AAAA"}
|
package/esm/index.d.mts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import { AnthropicThinkingMode } from "./thinking-mode.mjs";
|
|
2
|
-
import { 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";
|
|
4
|
+
import { AnthropicModel } from "./model.mjs";
|
|
3
5
|
import { AnthropicSDK } from "./sdk.mjs";
|
|
4
|
-
|
|
6
|
+
import { ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_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
|
+
export { ANTHROPIC_BLOCK_FORMAT, ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_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,3 +1,10 @@
|
|
|
1
|
+
import { ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_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";
|
|
7
|
+
import { AnthropicModel } from "./model.mjs";
|
|
1
8
|
import { AnthropicSDK } from "./sdk.mjs";
|
|
2
9
|
|
|
3
|
-
export { AnthropicSDK };
|
|
10
|
+
export { ANTHROPIC_BLOCK_FORMAT, ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_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,58 @@
|
|
|
1
|
+
import { ModelPricing } from "@warlock.js/ai";
|
|
2
|
+
|
|
3
|
+
//#region ../../packages/ai-anthropic/src/known-pricing.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Anthropic's prompt-cache write multipliers, relative to the base input
|
|
6
|
+
* rate: a 5-minute write costs 1.25x, a 1-hour write 2x. They hold for
|
|
7
|
+
* every Claude model on Anthropic's price list.
|
|
8
|
+
*
|
|
9
|
+
* Source: https://platform.claude.com/docs/en/about-claude/pricing
|
|
10
|
+
* (fetched 2026-10-17).
|
|
11
|
+
*/
|
|
12
|
+
declare const ANTHROPIC_CACHE_WRITE_MULTIPLIER = 1.25;
|
|
13
|
+
declare const ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER = 2;
|
|
14
|
+
/**
|
|
15
|
+
* Built-in Claude API list prices, USD per 1,000,000 tokens, keyed by
|
|
16
|
+
* model id. `cachedInput` is the cache-hit rate, `cacheWrite` the
|
|
17
|
+
* 5-minute write rate and `cacheWrite1h` the 1-hour write rate.
|
|
18
|
+
*
|
|
19
|
+
* Source: https://platform.claude.com/docs/en/about-claude/pricing,
|
|
20
|
+
* "Model pricing" table, fetched 2026-10-17. Standard (global) routing,
|
|
21
|
+
* non-batch. Not covered, so pass `pricing` yourself when you need them:
|
|
22
|
+
*
|
|
23
|
+
* - Claude Haiku 5.5 — priced by prompt length (higher rates above
|
|
24
|
+
* 100,000 prompt tokens), which a flat `ModelPricing` cannot express.
|
|
25
|
+
* - US-only inference (`inference_geo: "us"`, 1.1x), fast mode, the Batch
|
|
26
|
+
* API, and Claude on Bedrock / Vertex AI (partner-priced).
|
|
27
|
+
* - Limited-availability models (Mythos) and retired models.
|
|
28
|
+
*
|
|
29
|
+
* Dated snapshot ids (`claude-haiku-4-5-20251001`) resolve to their alias
|
|
30
|
+
* entry through {@link anthropicPricingFor}.
|
|
31
|
+
*/
|
|
32
|
+
declare const ANTHROPIC_MODEL_PRICING: Readonly<Record<string, ModelPricing>>;
|
|
33
|
+
/**
|
|
34
|
+
* Look up the built-in list price for a Claude model id. Accepts the
|
|
35
|
+
* alias (`claude-sonnet-4-5`) or a dated snapshot
|
|
36
|
+
* (`claude-sonnet-4-5-20250929`). Returns `undefined` for any id not in
|
|
37
|
+
* {@link ANTHROPIC_MODEL_PRICING}, so cost stays unknown rather than wrong.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* anthropicPricingFor("claude-haiku-4-5-20251001"); // { input: 1, output: 5, … }
|
|
41
|
+
* anthropicPricingFor("claude-haiku-5-5"); // undefined (prompt-length tiers)
|
|
42
|
+
*/
|
|
43
|
+
declare function anthropicPricingFor(modelName: string): ModelPricing | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Fill the cache-write rates Anthropic derives from the input rate
|
|
46
|
+
* (5-minute writes 1.25x, 1-hour writes 2x) into a pricing entry that
|
|
47
|
+
* omits them, so a caller who supplies only `{ input, output }` is no
|
|
48
|
+
* longer billed nothing for cache writes. Explicit rates always win; the
|
|
49
|
+
* cache-read rate is left alone because it differs per model.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* withAnthropicCacheWriteRates({ input: 3, output: 15 });
|
|
53
|
+
* // { input: 3, output: 15, cacheWrite: 3.75, cacheWrite1h: 6 }
|
|
54
|
+
*/
|
|
55
|
+
declare function withAnthropicCacheWriteRates(pricing: ModelPricing | undefined): ModelPricing | undefined;
|
|
56
|
+
//#endregion
|
|
57
|
+
export { ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_PRICING, anthropicPricingFor, withAnthropicCacheWriteRates };
|
|
58
|
+
//# 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":";;;;;AAUA;;;;AAA6C;AAC7C;cADa,gCAAA;AAAA,cACA,mCAAA;;AAAmC;AAoBhD;;;;;;;;;;;;AAA0E;AA+C1E;;;cA/Ca,uBAAA,EAAyB,QAAA,CAAS,MAAA,SAAe,YAAA;AA+CM;AAqBpE;;;;;;;;AAEe;AAvBqD,iBAApD,mBAAA,CAAoB,SAAA,WAAoB,YAAY;;;;;;;;;;;;iBAqBpD,4BAAA,CACd,OAAA,EAAS,YAAA,eACR,YAAY"}
|
|
@@ -0,0 +1,165 @@
|
|
|
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
|
+
|
|
163
|
+
//#endregion
|
|
164
|
+
export { ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_MULTIPLIER, ANTHROPIC_MODEL_PRICING, anthropicPricingFor, withAnthropicCacheWriteRates };
|
|
165
|
+
//# 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"],"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"known-vision-models.mjs","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"known-vision-models.mjs","names":[],"sources":["../../../../../../../packages/ai-anthropic/src/known-vision-models.ts"],"sourcesContent":["/**\n * Model-name prefixes for Claude families that accept image input\n * (vision) on the Messages API.\n *\n * Every Claude 3, Claude 3.5/3.7, Claude 4 and Claude 5 family model is\n * multimodal, so the list covers both the dotted legacy naming\n * (`claude-3-haiku-...`, `claude-3-5-sonnet-...`) and the current\n * `claude-<tier>-4-*` naming (`claude-opus-4-7`, `claude-sonnet-4-6`,\n * `claude-haiku-4-5`). Pre-3 families (`claude-2`, `claude-instant`)\n * are text-only and intentionally absent.\n *\n * The Claude 5 series is multimodal too (claude-api ref, cached\n * 2026-09-25): its vision examples use `claude-opus-5-5`; the models list\n * credits Claude Fable 5.1 with vision and Claude Sonnet 5 with\n * high-resolution vision; Claude Mythos 5.1 has \"same capabilities\" as\n * Fable 5.1. The tier-5 prefixes cover every 5.x release\n * (`claude-opus-5`, `claude-opus-5-5`, `claude-sonnet-5-5`,\n * `claude-fable-5-1`, …). Opus/Sonnet 4.6–4.8 are already covered by the\n * tier-4 prefixes.\n *\n * Matched as a prefix so dated variants (`claude-opus-4-20250514`) are\n * covered without listing every release tag. Devs can always override\n * per-model via `anthropic.model({ name, vision: true | false })` —\n * explicit config wins over inference in either direction.\n */\nconst VISION_CAPABLE_PREFIXES = [\n \"claude-3\",\n \"claude-4\",\n \"claude-opus-4\",\n \"claude-sonnet-4\",\n \"claude-haiku-4\",\n \"claude-opus-5\",\n \"claude-sonnet-5\",\n \"claude-fable-5\",\n \"claude-mythos-5\",\n];\n\n/**\n * Infer whether a given Claude model name supports vision based on the\n * known-prefix list. Unknown models default to `false` so that passing\n * an image attachment to an unsupported model surfaces a clear,\n * agent-side capability error instead of an opaque Anthropic 400.\n *\n * @example\n * inferVisionCapability(\"claude-sonnet-4-6\"); // → true\n * inferVisionCapability(\"claude-3-5-sonnet-latest\"); // → true\n * inferVisionCapability(\"claude-2.1\"); // → false\n * inferVisionCapability(\"custom-proxy-llm\"); // → false\n */\nexport function inferVisionCapability(modelName: string): boolean {\n const normalized = modelName.toLowerCase();\n\n return VISION_CAPABLE_PREFIXES.some((prefix) => normalized.startsWith(prefix));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAM,0BAA0B;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;;;AAcA,SAAgB,sBAAsB,WAA4B;CAChE,MAAM,aAAa,UAAU,YAAY;CAEzC,OAAO,wBAAwB,MAAM,WAAW,WAAW,WAAW,MAAM,CAAC;AAC/E"}
|