@ai-sdk/anthropic 4.0.32 → 4.0.34
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 +14 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +759 -192
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +804 -121
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +51 -0
- package/package.json +3 -3
- package/src/anthropic-language-model.ts +4 -4
- package/src/anthropic-messages-batch.ts +756 -0
- package/src/anthropic-provider.ts +7 -7
package/docs/05-anthropic.mdx
CHANGED
|
@@ -144,6 +144,57 @@ The following optional provider options are available for Anthropic models:
|
|
|
144
144
|
Optional. Metadata to include with the request. See the [Anthropic API documentation](https://platform.claude.com/docs/en/api/messages/create) for details.
|
|
145
145
|
- `userId` _string_ - An external identifier for the end-user. Should be a UUID, hash, or other opaque identifier. Must not contain PII.
|
|
146
146
|
|
|
147
|
+
### Text Batches
|
|
148
|
+
|
|
149
|
+
<Note type="warning">
|
|
150
|
+
Text batch support is experimental and the API may change in patch releases.
|
|
151
|
+
</Note>
|
|
152
|
+
|
|
153
|
+
Anthropic language models support asynchronous text generation through the
|
|
154
|
+
[Message Batches API](https://platform.claude.com/docs/en/build-with-claude/batch-processing).
|
|
155
|
+
Use the experimental text batch APIs to start a batch, poll its status, and
|
|
156
|
+
stream its results:
|
|
157
|
+
|
|
158
|
+
<Note>
|
|
159
|
+
Anthropic Message Batches do not support the `speed` option. Explicit
|
|
160
|
+
`anthropicBeta` values must be configured when starting the batch rather than
|
|
161
|
+
on an individual request.
|
|
162
|
+
</Note>
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
166
|
+
import {
|
|
167
|
+
experimental_getBatchResults as getBatchResults,
|
|
168
|
+
experimental_getBatchStatus as getBatchStatus,
|
|
169
|
+
experimental_startTextBatch as startTextBatch,
|
|
170
|
+
} from 'ai';
|
|
171
|
+
import { setTimeout } from 'node:timers/promises';
|
|
172
|
+
|
|
173
|
+
const model = anthropic('claude-haiku-4-5');
|
|
174
|
+
|
|
175
|
+
const batch = await startTextBatch({
|
|
176
|
+
model,
|
|
177
|
+
requests: [
|
|
178
|
+
{ id: 'first', prompt: 'What is the capital of France?' },
|
|
179
|
+
{ id: 'second', prompt: 'What is the capital of Germany?' },
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
let status = batch.status;
|
|
184
|
+
while (status === 'pending') {
|
|
185
|
+
await setTimeout(60_000);
|
|
186
|
+
({ status } = await getBatchStatus({ model, batch }));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
for await (const item of getBatchResults({ model, batch })) {
|
|
190
|
+
if (item.status === 'succeeded') {
|
|
191
|
+
console.log(item.id, item.text);
|
|
192
|
+
} else {
|
|
193
|
+
console.error(item.id, item.error);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
147
198
|
### Structured Outputs and Tool Input Streaming
|
|
148
199
|
|
|
149
200
|
Tool call streaming is enabled by default. You can opt out by setting the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/anthropic",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.34",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ai-sdk/provider": "4.0.
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
38
|
+
"@ai-sdk/provider": "4.0.6",
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.23"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "22.19.19",
|
|
@@ -127,7 +127,7 @@ function createCitationSource(
|
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
type AnthropicLanguageModelConfig = {
|
|
130
|
+
export type AnthropicLanguageModelConfig = {
|
|
131
131
|
provider: string;
|
|
132
132
|
baseURL: string;
|
|
133
133
|
headers?: Resolvable<Record<string, string | undefined>>;
|
|
@@ -157,7 +157,7 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
157
157
|
|
|
158
158
|
readonly modelId: AnthropicModelId;
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
protected readonly config: AnthropicLanguageModelConfig;
|
|
161
161
|
private readonly generateId: () => string;
|
|
162
162
|
|
|
163
163
|
static [WORKFLOW_SERIALIZE](model: AnthropicLanguageModel) {
|
|
@@ -202,7 +202,7 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
202
202
|
return this.config.supportedUrls?.() ?? {};
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
|
|
205
|
+
protected async getArgs({
|
|
206
206
|
userSuppliedBetas,
|
|
207
207
|
prompt,
|
|
208
208
|
maxOutputTokens,
|
|
@@ -876,7 +876,7 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
876
876
|
);
|
|
877
877
|
}
|
|
878
878
|
|
|
879
|
-
|
|
879
|
+
protected transformRequestBody(
|
|
880
880
|
args: Record<string, any>,
|
|
881
881
|
betas: Set<string>,
|
|
882
882
|
): Record<string, any> {
|