@wabot-dev/framework 0.1.0-beta.12 → 0.1.0-beta.13
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/dist/src/ai/claude/ClaudeChatBotAdapter.js +115 -0
- package/dist/src/core/Entity.js +2 -2
- package/dist/src/index.d.ts +11 -2
- package/dist/src/index.js +2 -1
- package/dist/src/node_modules/@anthropic-ai/sdk/_vendor/partial-json-parser/parser.js +221 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/client.js +540 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/core/api-promise.js +74 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/core/error.js +100 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/core/pagination.js +119 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/core/resource.js +8 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/core/streaming.js +283 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/constants.js +16 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/decoders/jsonl.js +37 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/decoders/line.js +110 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/detect-platform.js +159 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/errors.js +37 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/headers.js +71 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/parse.js +53 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/request-options.js +11 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/shims.js +86 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/to-file.js +94 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/tslib.js +14 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/uploads.js +113 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/bytes.js +27 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/env.js +19 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/log.js +82 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/path.js +76 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/sleep.js +4 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/uuid.js +16 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/internal/utils/values.js +48 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/lib/BetaMessageStream.js +588 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/lib/MessageStream.js +582 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/resources/beta/beta.js +19 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/resources/beta/files.js +120 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/resources/beta/messages/batches.js +202 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/resources/beta/messages/messages.js +85 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/resources/beta/models.js +58 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/resources/completions.js +21 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/resources/messages/batches.js +151 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/resources/messages/messages.js +71 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/resources/models.js +43 -0
- package/dist/src/node_modules/@anthropic-ai/sdk/version.js +3 -0
- package/package.json +2 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { APIResource } from '../../core/resource.js';
|
|
2
|
+
import { Page } from '../../core/pagination.js';
|
|
3
|
+
import { buildHeaders } from '../../internal/headers.js';
|
|
4
|
+
import { multipartFormRequestOptions } from '../../internal/uploads.js';
|
|
5
|
+
import { path } from '../../internal/utils/path.js';
|
|
6
|
+
|
|
7
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8
|
+
class Files extends APIResource {
|
|
9
|
+
/**
|
|
10
|
+
* List Files
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // Automatically fetches more pages as needed.
|
|
15
|
+
* for await (const fileMetadata of client.beta.files.list()) {
|
|
16
|
+
* // ...
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
list(params = {}, options) {
|
|
21
|
+
const { betas, ...query } = params ?? {};
|
|
22
|
+
return this._client.getAPIList('/v1/files', (Page), {
|
|
23
|
+
query,
|
|
24
|
+
...options,
|
|
25
|
+
headers: buildHeaders([
|
|
26
|
+
{ 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
|
|
27
|
+
options?.headers,
|
|
28
|
+
]),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Delete File
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const deletedFile = await client.beta.files.delete(
|
|
37
|
+
* 'file_id',
|
|
38
|
+
* );
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
delete(fileID, params = {}, options) {
|
|
42
|
+
const { betas } = params ?? {};
|
|
43
|
+
return this._client.delete(path `/v1/files/${fileID}`, {
|
|
44
|
+
...options,
|
|
45
|
+
headers: buildHeaders([
|
|
46
|
+
{ 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
|
|
47
|
+
options?.headers,
|
|
48
|
+
]),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Download File
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const response = await client.beta.files.download(
|
|
57
|
+
* 'file_id',
|
|
58
|
+
* );
|
|
59
|
+
*
|
|
60
|
+
* const content = await response.blob();
|
|
61
|
+
* console.log(content);
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
download(fileID, params = {}, options) {
|
|
65
|
+
const { betas } = params ?? {};
|
|
66
|
+
return this._client.get(path `/v1/files/${fileID}/content`, {
|
|
67
|
+
...options,
|
|
68
|
+
headers: buildHeaders([
|
|
69
|
+
{
|
|
70
|
+
'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString(),
|
|
71
|
+
Accept: 'application/binary',
|
|
72
|
+
},
|
|
73
|
+
options?.headers,
|
|
74
|
+
]),
|
|
75
|
+
__binaryResponse: true,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get File Metadata
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* const fileMetadata =
|
|
84
|
+
* await client.beta.files.retrieveMetadata('file_id');
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
retrieveMetadata(fileID, params = {}, options) {
|
|
88
|
+
const { betas } = params ?? {};
|
|
89
|
+
return this._client.get(path `/v1/files/${fileID}`, {
|
|
90
|
+
...options,
|
|
91
|
+
headers: buildHeaders([
|
|
92
|
+
{ 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
|
|
93
|
+
options?.headers,
|
|
94
|
+
]),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Upload File
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* const fileMetadata = await client.beta.files.upload({
|
|
103
|
+
* file: fs.createReadStream('path/to/file'),
|
|
104
|
+
* });
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
upload(params, options) {
|
|
108
|
+
const { betas, ...body } = params;
|
|
109
|
+
return this._client.post('/v1/files', multipartFormRequestOptions({
|
|
110
|
+
body,
|
|
111
|
+
...options,
|
|
112
|
+
headers: buildHeaders([
|
|
113
|
+
{ 'anthropic-beta': [...(betas ?? []), 'files-api-2025-04-14'].toString() },
|
|
114
|
+
options?.headers,
|
|
115
|
+
]),
|
|
116
|
+
}, this._client));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export { Files };
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { APIResource } from '../../../core/resource.js';
|
|
2
|
+
import { Page } from '../../../core/pagination.js';
|
|
3
|
+
import { buildHeaders } from '../../../internal/headers.js';
|
|
4
|
+
import { JSONLDecoder } from '../../../internal/decoders/jsonl.js';
|
|
5
|
+
import { AnthropicError } from '../../../core/error.js';
|
|
6
|
+
import { path } from '../../../internal/utils/path.js';
|
|
7
|
+
|
|
8
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
9
|
+
class Batches extends APIResource {
|
|
10
|
+
/**
|
|
11
|
+
* Send a batch of Message creation requests.
|
|
12
|
+
*
|
|
13
|
+
* The Message Batches API can be used to process multiple Messages API requests at
|
|
14
|
+
* once. Once a Message Batch is created, it begins processing immediately. Batches
|
|
15
|
+
* can take up to 24 hours to complete.
|
|
16
|
+
*
|
|
17
|
+
* Learn more about the Message Batches API in our
|
|
18
|
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const betaMessageBatch =
|
|
23
|
+
* await client.beta.messages.batches.create({
|
|
24
|
+
* requests: [
|
|
25
|
+
* {
|
|
26
|
+
* custom_id: 'my-custom-id-1',
|
|
27
|
+
* params: {
|
|
28
|
+
* max_tokens: 1024,
|
|
29
|
+
* messages: [
|
|
30
|
+
* { content: 'Hello, world', role: 'user' },
|
|
31
|
+
* ],
|
|
32
|
+
* model: 'claude-sonnet-4-20250514',
|
|
33
|
+
* },
|
|
34
|
+
* },
|
|
35
|
+
* ],
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
create(params, options) {
|
|
40
|
+
const { betas, ...body } = params;
|
|
41
|
+
return this._client.post('/v1/messages/batches?beta=true', {
|
|
42
|
+
body,
|
|
43
|
+
...options,
|
|
44
|
+
headers: buildHeaders([
|
|
45
|
+
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
|
46
|
+
options?.headers,
|
|
47
|
+
]),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* This endpoint is idempotent and can be used to poll for Message Batch
|
|
52
|
+
* completion. To access the results of a Message Batch, make a request to the
|
|
53
|
+
* `results_url` field in the response.
|
|
54
|
+
*
|
|
55
|
+
* Learn more about the Message Batches API in our
|
|
56
|
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const betaMessageBatch =
|
|
61
|
+
* await client.beta.messages.batches.retrieve(
|
|
62
|
+
* 'message_batch_id',
|
|
63
|
+
* );
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
retrieve(messageBatchID, params = {}, options) {
|
|
67
|
+
const { betas } = params ?? {};
|
|
68
|
+
return this._client.get(path `/v1/messages/batches/${messageBatchID}?beta=true`, {
|
|
69
|
+
...options,
|
|
70
|
+
headers: buildHeaders([
|
|
71
|
+
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
|
72
|
+
options?.headers,
|
|
73
|
+
]),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* List all Message Batches within a Workspace. Most recently created batches are
|
|
78
|
+
* returned first.
|
|
79
|
+
*
|
|
80
|
+
* Learn more about the Message Batches API in our
|
|
81
|
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* // Automatically fetches more pages as needed.
|
|
86
|
+
* for await (const betaMessageBatch of client.beta.messages.batches.list()) {
|
|
87
|
+
* // ...
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
list(params = {}, options) {
|
|
92
|
+
const { betas, ...query } = params ?? {};
|
|
93
|
+
return this._client.getAPIList('/v1/messages/batches?beta=true', (Page), {
|
|
94
|
+
query,
|
|
95
|
+
...options,
|
|
96
|
+
headers: buildHeaders([
|
|
97
|
+
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
|
98
|
+
options?.headers,
|
|
99
|
+
]),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Delete a Message Batch.
|
|
104
|
+
*
|
|
105
|
+
* Message Batches can only be deleted once they've finished processing. If you'd
|
|
106
|
+
* like to delete an in-progress batch, you must first cancel it.
|
|
107
|
+
*
|
|
108
|
+
* Learn more about the Message Batches API in our
|
|
109
|
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const betaDeletedMessageBatch =
|
|
114
|
+
* await client.beta.messages.batches.delete(
|
|
115
|
+
* 'message_batch_id',
|
|
116
|
+
* );
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
delete(messageBatchID, params = {}, options) {
|
|
120
|
+
const { betas } = params ?? {};
|
|
121
|
+
return this._client.delete(path `/v1/messages/batches/${messageBatchID}?beta=true`, {
|
|
122
|
+
...options,
|
|
123
|
+
headers: buildHeaders([
|
|
124
|
+
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
|
125
|
+
options?.headers,
|
|
126
|
+
]),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Batches may be canceled any time before processing ends. Once cancellation is
|
|
131
|
+
* initiated, the batch enters a `canceling` state, at which time the system may
|
|
132
|
+
* complete any in-progress, non-interruptible requests before finalizing
|
|
133
|
+
* cancellation.
|
|
134
|
+
*
|
|
135
|
+
* The number of canceled requests is specified in `request_counts`. To determine
|
|
136
|
+
* which requests were canceled, check the individual results within the batch.
|
|
137
|
+
* Note that cancellation may not result in any canceled requests if they were
|
|
138
|
+
* non-interruptible.
|
|
139
|
+
*
|
|
140
|
+
* Learn more about the Message Batches API in our
|
|
141
|
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const betaMessageBatch =
|
|
146
|
+
* await client.beta.messages.batches.cancel(
|
|
147
|
+
* 'message_batch_id',
|
|
148
|
+
* );
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
cancel(messageBatchID, params = {}, options) {
|
|
152
|
+
const { betas } = params ?? {};
|
|
153
|
+
return this._client.post(path `/v1/messages/batches/${messageBatchID}/cancel?beta=true`, {
|
|
154
|
+
...options,
|
|
155
|
+
headers: buildHeaders([
|
|
156
|
+
{ 'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString() },
|
|
157
|
+
options?.headers,
|
|
158
|
+
]),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Streams the results of a Message Batch as a `.jsonl` file.
|
|
163
|
+
*
|
|
164
|
+
* Each line in the file is a JSON object containing the result of a single request
|
|
165
|
+
* in the Message Batch. Results are not guaranteed to be in the same order as
|
|
166
|
+
* requests. Use the `custom_id` field to match results to requests.
|
|
167
|
+
*
|
|
168
|
+
* Learn more about the Message Batches API in our
|
|
169
|
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* const betaMessageBatchIndividualResponse =
|
|
174
|
+
* await client.beta.messages.batches.results(
|
|
175
|
+
* 'message_batch_id',
|
|
176
|
+
* );
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
async results(messageBatchID, params = {}, options) {
|
|
180
|
+
const batch = await this.retrieve(messageBatchID);
|
|
181
|
+
if (!batch.results_url) {
|
|
182
|
+
throw new AnthropicError(`No batch \`results_url\`; Has it finished processing? ${batch.processing_status} - ${batch.id}`);
|
|
183
|
+
}
|
|
184
|
+
const { betas } = params ?? {};
|
|
185
|
+
return this._client
|
|
186
|
+
.get(batch.results_url, {
|
|
187
|
+
...options,
|
|
188
|
+
headers: buildHeaders([
|
|
189
|
+
{
|
|
190
|
+
'anthropic-beta': [...(betas ?? []), 'message-batches-2024-09-24'].toString(),
|
|
191
|
+
Accept: 'application/binary',
|
|
192
|
+
},
|
|
193
|
+
options?.headers,
|
|
194
|
+
]),
|
|
195
|
+
stream: true,
|
|
196
|
+
__binaryResponse: true,
|
|
197
|
+
})
|
|
198
|
+
._thenUnwrap((_, props) => JSONLDecoder.fromResponse(props.response, props.controller));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export { Batches };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { APIResource } from '../../../core/resource.js';
|
|
2
|
+
import { Batches } from './batches.js';
|
|
3
|
+
import { buildHeaders } from '../../../internal/headers.js';
|
|
4
|
+
import { BetaMessageStream } from '../../../lib/BetaMessageStream.js';
|
|
5
|
+
import { MODEL_NONSTREAMING_TOKENS } from '../../../internal/constants.js';
|
|
6
|
+
|
|
7
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
8
|
+
const DEPRECATED_MODELS = {
|
|
9
|
+
'claude-1.3': 'November 6th, 2024',
|
|
10
|
+
'claude-1.3-100k': 'November 6th, 2024',
|
|
11
|
+
'claude-instant-1.1': 'November 6th, 2024',
|
|
12
|
+
'claude-instant-1.1-100k': 'November 6th, 2024',
|
|
13
|
+
'claude-instant-1.2': 'November 6th, 2024',
|
|
14
|
+
'claude-3-sonnet-20240229': 'July 21st, 2025',
|
|
15
|
+
'claude-3-opus-20240229': 'January 5th, 2026',
|
|
16
|
+
'claude-2.1': 'July 21st, 2025',
|
|
17
|
+
'claude-2.0': 'July 21st, 2025',
|
|
18
|
+
'claude-3-5-sonnet-20241022': 'October 22, 2025',
|
|
19
|
+
'claude-3-5-sonnet-20240620': 'October 22, 2025',
|
|
20
|
+
};
|
|
21
|
+
class Messages extends APIResource {
|
|
22
|
+
constructor() {
|
|
23
|
+
super(...arguments);
|
|
24
|
+
this.batches = new Batches(this._client);
|
|
25
|
+
}
|
|
26
|
+
create(params, options) {
|
|
27
|
+
const { betas, ...body } = params;
|
|
28
|
+
if (body.model in DEPRECATED_MODELS) {
|
|
29
|
+
console.warn(`The model '${body.model}' is deprecated and will reach end-of-life on ${DEPRECATED_MODELS[body.model]}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`);
|
|
30
|
+
}
|
|
31
|
+
let timeout = this._client._options.timeout;
|
|
32
|
+
if (!body.stream && timeout == null) {
|
|
33
|
+
const maxNonstreamingTokens = MODEL_NONSTREAMING_TOKENS[body.model] ?? undefined;
|
|
34
|
+
timeout = this._client.calculateNonstreamingTimeout(body.max_tokens, maxNonstreamingTokens);
|
|
35
|
+
}
|
|
36
|
+
return this._client.post('/v1/messages?beta=true', {
|
|
37
|
+
body,
|
|
38
|
+
timeout: timeout ?? 600000,
|
|
39
|
+
...options,
|
|
40
|
+
headers: buildHeaders([
|
|
41
|
+
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
|
42
|
+
options?.headers,
|
|
43
|
+
]),
|
|
44
|
+
stream: params.stream ?? false,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a Message stream
|
|
49
|
+
*/
|
|
50
|
+
stream(body, options) {
|
|
51
|
+
return BetaMessageStream.createMessage(this, body, options);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Count the number of tokens in a Message.
|
|
55
|
+
*
|
|
56
|
+
* The Token Count API can be used to count the number of tokens in a Message,
|
|
57
|
+
* including tools, images, and documents, without creating it.
|
|
58
|
+
*
|
|
59
|
+
* Learn more about token counting in our
|
|
60
|
+
* [user guide](/en/docs/build-with-claude/token-counting)
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const betaMessageTokensCount =
|
|
65
|
+
* await client.beta.messages.countTokens({
|
|
66
|
+
* messages: [{ content: 'string', role: 'user' }],
|
|
67
|
+
* model: 'claude-3-7-sonnet-latest',
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
countTokens(params, options) {
|
|
72
|
+
const { betas, ...body } = params;
|
|
73
|
+
return this._client.post('/v1/messages/count_tokens?beta=true', {
|
|
74
|
+
body,
|
|
75
|
+
...options,
|
|
76
|
+
headers: buildHeaders([
|
|
77
|
+
{ 'anthropic-beta': [...(betas ?? []), 'token-counting-2024-11-01'].toString() },
|
|
78
|
+
options?.headers,
|
|
79
|
+
]),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
Messages.Batches = Batches;
|
|
84
|
+
|
|
85
|
+
export { Messages };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { APIResource } from '../../core/resource.js';
|
|
2
|
+
import { Page } from '../../core/pagination.js';
|
|
3
|
+
import { buildHeaders } from '../../internal/headers.js';
|
|
4
|
+
import { path } from '../../internal/utils/path.js';
|
|
5
|
+
|
|
6
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
7
|
+
class Models extends APIResource {
|
|
8
|
+
/**
|
|
9
|
+
* Get a specific model.
|
|
10
|
+
*
|
|
11
|
+
* The Models API response can be used to determine information about a specific
|
|
12
|
+
* model or resolve a model alias to a model ID.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const betaModelInfo = await client.beta.models.retrieve(
|
|
17
|
+
* 'model_id',
|
|
18
|
+
* );
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
retrieve(modelID, params = {}, options) {
|
|
22
|
+
const { betas } = params ?? {};
|
|
23
|
+
return this._client.get(path `/v1/models/${modelID}?beta=true`, {
|
|
24
|
+
...options,
|
|
25
|
+
headers: buildHeaders([
|
|
26
|
+
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
|
27
|
+
options?.headers,
|
|
28
|
+
]),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* List available models.
|
|
33
|
+
*
|
|
34
|
+
* The Models API response can be used to determine which models are available for
|
|
35
|
+
* use in the API. More recently released models are listed first.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* // Automatically fetches more pages as needed.
|
|
40
|
+
* for await (const betaModelInfo of client.beta.models.list()) {
|
|
41
|
+
* // ...
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
list(params = {}, options) {
|
|
46
|
+
const { betas, ...query } = params ?? {};
|
|
47
|
+
return this._client.getAPIList('/v1/models?beta=true', (Page), {
|
|
48
|
+
query,
|
|
49
|
+
...options,
|
|
50
|
+
headers: buildHeaders([
|
|
51
|
+
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
|
52
|
+
options?.headers,
|
|
53
|
+
]),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { Models };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { APIResource } from '../core/resource.js';
|
|
2
|
+
import { buildHeaders } from '../internal/headers.js';
|
|
3
|
+
|
|
4
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5
|
+
class Completions extends APIResource {
|
|
6
|
+
create(params, options) {
|
|
7
|
+
const { betas, ...body } = params;
|
|
8
|
+
return this._client.post('/v1/complete', {
|
|
9
|
+
body,
|
|
10
|
+
timeout: this._client._options.timeout ?? 600000,
|
|
11
|
+
...options,
|
|
12
|
+
headers: buildHeaders([
|
|
13
|
+
{ ...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined) },
|
|
14
|
+
options?.headers,
|
|
15
|
+
]),
|
|
16
|
+
stream: params.stream ?? false,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { Completions };
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { APIResource } from '../../core/resource.js';
|
|
2
|
+
import { Page } from '../../core/pagination.js';
|
|
3
|
+
import { buildHeaders } from '../../internal/headers.js';
|
|
4
|
+
import { JSONLDecoder } from '../../internal/decoders/jsonl.js';
|
|
5
|
+
import { AnthropicError } from '../../core/error.js';
|
|
6
|
+
import { path } from '../../internal/utils/path.js';
|
|
7
|
+
|
|
8
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
9
|
+
class Batches extends APIResource {
|
|
10
|
+
/**
|
|
11
|
+
* Send a batch of Message creation requests.
|
|
12
|
+
*
|
|
13
|
+
* The Message Batches API can be used to process multiple Messages API requests at
|
|
14
|
+
* once. Once a Message Batch is created, it begins processing immediately. Batches
|
|
15
|
+
* can take up to 24 hours to complete.
|
|
16
|
+
*
|
|
17
|
+
* Learn more about the Message Batches API in our
|
|
18
|
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const messageBatch = await client.messages.batches.create({
|
|
23
|
+
* requests: [
|
|
24
|
+
* {
|
|
25
|
+
* custom_id: 'my-custom-id-1',
|
|
26
|
+
* params: {
|
|
27
|
+
* max_tokens: 1024,
|
|
28
|
+
* messages: [
|
|
29
|
+
* { content: 'Hello, world', role: 'user' },
|
|
30
|
+
* ],
|
|
31
|
+
* model: 'claude-sonnet-4-20250514',
|
|
32
|
+
* },
|
|
33
|
+
* },
|
|
34
|
+
* ],
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
create(body, options) {
|
|
39
|
+
return this._client.post('/v1/messages/batches', { body, ...options });
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* This endpoint is idempotent and can be used to poll for Message Batch
|
|
43
|
+
* completion. To access the results of a Message Batch, make a request to the
|
|
44
|
+
* `results_url` field in the response.
|
|
45
|
+
*
|
|
46
|
+
* Learn more about the Message Batches API in our
|
|
47
|
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const messageBatch = await client.messages.batches.retrieve(
|
|
52
|
+
* 'message_batch_id',
|
|
53
|
+
* );
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
retrieve(messageBatchID, options) {
|
|
57
|
+
return this._client.get(path `/v1/messages/batches/${messageBatchID}`, options);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* List all Message Batches within a Workspace. Most recently created batches are
|
|
61
|
+
* returned first.
|
|
62
|
+
*
|
|
63
|
+
* Learn more about the Message Batches API in our
|
|
64
|
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* // Automatically fetches more pages as needed.
|
|
69
|
+
* for await (const messageBatch of client.messages.batches.list()) {
|
|
70
|
+
* // ...
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
list(query = {}, options) {
|
|
75
|
+
return this._client.getAPIList('/v1/messages/batches', (Page), { query, ...options });
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Delete a Message Batch.
|
|
79
|
+
*
|
|
80
|
+
* Message Batches can only be deleted once they've finished processing. If you'd
|
|
81
|
+
* like to delete an in-progress batch, you must first cancel it.
|
|
82
|
+
*
|
|
83
|
+
* Learn more about the Message Batches API in our
|
|
84
|
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const deletedMessageBatch =
|
|
89
|
+
* await client.messages.batches.delete('message_batch_id');
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
delete(messageBatchID, options) {
|
|
93
|
+
return this._client.delete(path `/v1/messages/batches/${messageBatchID}`, options);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Batches may be canceled any time before processing ends. Once cancellation is
|
|
97
|
+
* initiated, the batch enters a `canceling` state, at which time the system may
|
|
98
|
+
* complete any in-progress, non-interruptible requests before finalizing
|
|
99
|
+
* cancellation.
|
|
100
|
+
*
|
|
101
|
+
* The number of canceled requests is specified in `request_counts`. To determine
|
|
102
|
+
* which requests were canceled, check the individual results within the batch.
|
|
103
|
+
* Note that cancellation may not result in any canceled requests if they were
|
|
104
|
+
* non-interruptible.
|
|
105
|
+
*
|
|
106
|
+
* Learn more about the Message Batches API in our
|
|
107
|
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* const messageBatch = await client.messages.batches.cancel(
|
|
112
|
+
* 'message_batch_id',
|
|
113
|
+
* );
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
cancel(messageBatchID, options) {
|
|
117
|
+
return this._client.post(path `/v1/messages/batches/${messageBatchID}/cancel`, options);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Streams the results of a Message Batch as a `.jsonl` file.
|
|
121
|
+
*
|
|
122
|
+
* Each line in the file is a JSON object containing the result of a single request
|
|
123
|
+
* in the Message Batch. Results are not guaranteed to be in the same order as
|
|
124
|
+
* requests. Use the `custom_id` field to match results to requests.
|
|
125
|
+
*
|
|
126
|
+
* Learn more about the Message Batches API in our
|
|
127
|
+
* [user guide](/en/docs/build-with-claude/batch-processing)
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* const messageBatchIndividualResponse =
|
|
132
|
+
* await client.messages.batches.results('message_batch_id');
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
async results(messageBatchID, options) {
|
|
136
|
+
const batch = await this.retrieve(messageBatchID);
|
|
137
|
+
if (!batch.results_url) {
|
|
138
|
+
throw new AnthropicError(`No batch \`results_url\`; Has it finished processing? ${batch.processing_status} - ${batch.id}`);
|
|
139
|
+
}
|
|
140
|
+
return this._client
|
|
141
|
+
.get(batch.results_url, {
|
|
142
|
+
...options,
|
|
143
|
+
headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),
|
|
144
|
+
stream: true,
|
|
145
|
+
__binaryResponse: true,
|
|
146
|
+
})
|
|
147
|
+
._thenUnwrap((_, props) => JSONLDecoder.fromResponse(props.response, props.controller));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export { Batches };
|