ai-sdk-anthropic 0.0.1 → 0.0.3
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/README.md +38 -0
- package/package.json +11 -3
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# ai-sdk-anthropic
|
|
2
|
+
|
|
3
|
+
Thin wrapper around `@ai-sdk/anthropic` that fixes token usage in streaming
|
|
4
|
+
responses by pulling `input_tokens` and `cache_read_input_tokens` from the
|
|
5
|
+
provider metadata when they are missing from the standard usage payload.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i ai-sdk-anthropic
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { anthropic, createAnthropic } from "ai-sdk-anthropic";
|
|
17
|
+
|
|
18
|
+
// default provider
|
|
19
|
+
const model = anthropic("claude-3-5-sonnet-20241022");
|
|
20
|
+
|
|
21
|
+
// or customize the provider
|
|
22
|
+
const custom = createAnthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
|
|
23
|
+
const customModel = custom("claude-3-5-sonnet-20241022");
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## What changes
|
|
27
|
+
|
|
28
|
+
- For streamed responses, if `usage.inputTokens` or `usage.cachedInputTokens`
|
|
29
|
+
is missing or zero, the wrapper fills them from the raw Anthropic usage
|
|
30
|
+
metadata when available.
|
|
31
|
+
- `usage.totalTokens` is recomputed when both `inputTokens` and `outputTokens`
|
|
32
|
+
are known.
|
|
33
|
+
|
|
34
|
+
## Exports
|
|
35
|
+
|
|
36
|
+
- `createAnthropic(options?)`
|
|
37
|
+
- `anthropic`
|
|
38
|
+
- `VERSION` (re-exported from `@ai-sdk/anthropic`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-sdk-anthropic",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -27,5 +27,13 @@
|
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"zod": "^3.25.76 || ^4.1.8"
|
|
30
|
-
}
|
|
31
|
-
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/caozhiyuan/ai-sdk-anthropic.git"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/caozhiyuan/ai-sdk-anthropic/issues"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/caozhiyuan/ai-sdk-anthropic#readme"
|
|
39
|
+
}
|