@ai-sdk/anthropic 4.0.113 → 4.0.114

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.
@@ -1587,6 +1587,8 @@ Shorter prompts cannot be cached, even if marked with `cacheControl`. Any reques
1587
1587
 
1588
1588
  For more on prompt caching with Anthropic, see [Anthropic's Cache Control documentation](https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching).
1589
1589
 
1590
+ If the number of cached tokens drops after you load the conversation history from a database, see [Prompt Cache Misses With Stored Messages](/docs/troubleshooting/prompt-cache-misses-with-stored-messages).
1591
+
1590
1592
  <Note type="warning">
1591
1593
  Because the `UIMessage` type (used by AI SDK UI hooks like `useChat`) does not
1592
1594
  support the `providerOptions` property, you can use `convertToModelMessages`
@@ -2836,6 +2838,17 @@ and the `mediaType` should be set to `'application/pdf'`.
2836
2838
 
2837
2839
  ### Model Capabilities
2838
2840
 
2841
+ Use `anthropicModelCapabilities(modelId)` to look up a model's capabilities and
2842
+ provider options for the Messages API. Model IDs have autocomplete, and the lookup
2843
+ requires no API call. It returns `undefined` for unknown model IDs.
2844
+
2845
+ ```ts
2846
+ import { anthropicModelCapabilities } from '@ai-sdk/anthropic';
2847
+
2848
+ const model = anthropicModelCapabilities('claude-sonnet-5-5');
2849
+ console.log(model?.endpoints.messages);
2850
+ ```
2851
+
2839
2852
  <Note>
2840
2853
  `claude-opus-4-0`, `claude-opus-4-1`, and `claude-sonnet-4-0` are hidden from
2841
2854
  this catalog because requests returned 404s. Their historical capability
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/anthropic",
3
- "version": "4.0.113",
3
+ "version": "4.0.114",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@ai-sdk/provider": "4.0.40",
39
- "@ai-sdk/provider-utils": "5.0.87"
39
+ "@ai-sdk/provider-utils": "5.0.88"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@ai-sdk/test-server": "2.0.4",
@@ -1154,7 +1154,6 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
1154
1154
  type: 'other',
1155
1155
  message: `Unknown context management strategy: ${strategy}`,
1156
1156
  });
1157
- return undefined;
1158
1157
  }
1159
1158
  })
1160
1159
  .filter(edit => edit !== undefined),
@@ -689,6 +689,48 @@ export const anthropicModelCatalog: Readonly<
689
689
  .map(([modelId]) => [modelId, listedLanguageModelEntries[modelId]]),
690
690
  );
691
691
 
692
+ /**
693
+ * Returns Messages API catalog metadata, or `undefined` for unlisted IDs.
694
+ */
695
+ export function anthropicModelCapabilities(
696
+ modelId: AnthropicModelIds['language'] | (string & {}),
697
+ ) {
698
+ if (!Object.prototype.hasOwnProperty.call(anthropicModelCatalog, modelId)) {
699
+ return;
700
+ }
701
+
702
+ const entry = anthropicModelCatalog[modelId];
703
+ const { supportsXhighEffort: _supportsXhighEffort, ...reasoning } =
704
+ entry.capabilities.language.reasoning;
705
+ return {
706
+ provider: 'anthropic' as const,
707
+ modelId,
708
+ endpoints: {
709
+ messages: {
710
+ operation: 'language' as const,
711
+ capabilities: { ...entry.capabilities.language, reasoning },
712
+ providerOptions: Object.fromEntries(
713
+ Object.entries(anthropicProviderOptions.language).map(
714
+ ([name, definition]) => [
715
+ name,
716
+ {
717
+ ...definition,
718
+ support:
719
+ entry.providerOptions.language[
720
+ name as AnthropicLanguageProviderOption
721
+ ],
722
+ },
723
+ ],
724
+ ),
725
+ ) as Record<
726
+ AnthropicLanguageProviderOption,
727
+ ProviderOptionDefinition & { support: ModelCapability }
728
+ >,
729
+ },
730
+ },
731
+ };
732
+ }
733
+
692
734
  export function getAnthropicLanguageModelEntry(
693
735
  modelId: string,
694
736
  ): AnthropicLanguageModelEntry {
@@ -819,7 +819,7 @@ export async function convertToAnthropicPrompt({
819
819
  message: `unsupported tool content part type: ${contentPart.type} with media type: ${contentPart.mediaType}`,
820
820
  });
821
821
 
822
- return undefined;
822
+ return;
823
823
  }
824
824
 
825
825
  warnings.push({
@@ -827,7 +827,7 @@ export async function convertToAnthropicPrompt({
827
827
  message: `unsupported tool content part type: ${contentPart.type} with data type: ${contentPart.data.type}`,
828
828
  });
829
829
 
830
- return undefined;
830
+ return;
831
831
  }
832
832
  case 'custom': {
833
833
  const anthropicOptions = contentPart.providerOptions
@@ -844,15 +844,13 @@ export async function convertToAnthropicPrompt({
844
844
  type: 'other',
845
845
  message: `unsupported custom tool content part`,
846
846
  });
847
- return undefined;
847
+ return;
848
848
  }
849
849
  default: {
850
850
  warnings.push({
851
851
  type: 'other',
852
852
  message: `unsupported tool content part type: ${(contentPart as { type: string }).type}`,
853
853
  });
854
-
855
- return undefined;
856
854
  }
857
855
  }
858
856
  })
package/src/index.ts CHANGED
@@ -14,6 +14,7 @@ export type {
14
14
  } from './anthropic-language-model-options';
15
15
  export type { AnthropicToolOptions } from './anthropic-prepare-tools';
16
16
  export { anthropic, createAnthropic } from './anthropic-provider';
17
+ export { anthropicModelCapabilities } from './anthropic-model-catalog';
17
18
  export type {
18
19
  AnthropicProvider,
19
20
  AnthropicProviderSettings,