@mastra/claude 1.0.0 → 1.0.1-alpha.1
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/package.json +8 -6
- package/src/Claude.test.ts +7 -18
- package/src/assets/claude.png +0 -0
- package/src/client/index.ts +4 -0
- package/src/client/schemas.gen.ts +1182 -0
- package/src/client/service-comments.ts +14 -0
- package/src/client/services.gen.ts +63 -0
- package/src/client/types.gen.ts +933 -0
- package/src/client/zodSchema.ts +337 -0
- package/src/index.ts +43 -52
- package/src/assets/claude.svg +0 -64
- package/src/openapi-components.ts +0 -467
- package/src/openapi-paths.ts +0 -85
- package/src/openapi.ts +0 -286
|
@@ -0,0 +1,1182 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
export const CreateMessageRequestSchema = {
|
|
4
|
+
required: ['model', 'messages', 'max_tokens'],
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
model: {
|
|
8
|
+
title: 'Model',
|
|
9
|
+
anyOf: [
|
|
10
|
+
{
|
|
11
|
+
type: 'string',
|
|
12
|
+
description: 'The ID of the model to use for this request.',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
title: 'Models',
|
|
16
|
+
enum: [
|
|
17
|
+
'claude-3-5-sonnet-latest',
|
|
18
|
+
'claude-3-5-sonnet-20241022',
|
|
19
|
+
'claude-3-5-sonnet-20240620',
|
|
20
|
+
'claude-3-opus-latest',
|
|
21
|
+
'claude-3-opus-20240229',
|
|
22
|
+
'claude-3-sonnet-20240229',
|
|
23
|
+
'claude-3-haiku-20240307',
|
|
24
|
+
'claude-2.1',
|
|
25
|
+
'claude-2.0',
|
|
26
|
+
'claude-instant-1.2',
|
|
27
|
+
],
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: `Available models. Mind that the list may not be exhaustive nor up-to-date.
|
|
30
|
+
`,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
description: `The model that will complete your prompt.
|
|
34
|
+
|
|
35
|
+
See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
|
36
|
+
details and options.
|
|
37
|
+
`,
|
|
38
|
+
example: 'claude-3-5-sonnet-20241022',
|
|
39
|
+
},
|
|
40
|
+
messages: {
|
|
41
|
+
minItems: 1,
|
|
42
|
+
type: 'array',
|
|
43
|
+
items: {
|
|
44
|
+
$ref: '#/components/schemas/Message',
|
|
45
|
+
},
|
|
46
|
+
description: `Input messages.
|
|
47
|
+
|
|
48
|
+
Our models are trained to operate on alternating \`user\` and \`assistant\`
|
|
49
|
+
conversational turns. When creating a new \`Message\`, you specify the prior
|
|
50
|
+
conversational turns with the \`messages\` parameter, and the model then generates
|
|
51
|
+
the next \`Message\` in the conversation.
|
|
52
|
+
|
|
53
|
+
Each input message must be an object with a \`role\` and \`content\`. You can
|
|
54
|
+
specify a single \`user\`-role message, or you can include multiple \`user\` and
|
|
55
|
+
\`assistant\` messages. The first message must always use the \`user\` role.
|
|
56
|
+
|
|
57
|
+
If the final message uses the \`assistant\` role, the response content will
|
|
58
|
+
continue immediately from the content in that message. This can be used to
|
|
59
|
+
constrain part of the model's response.
|
|
60
|
+
|
|
61
|
+
See [message content](https://docs.anthropic.com/en/api/messages-content) for
|
|
62
|
+
details on how to construct valid message objects.
|
|
63
|
+
|
|
64
|
+
Example with a single \`user\` message:
|
|
65
|
+
|
|
66
|
+
\`\`\`json
|
|
67
|
+
[{ "role": "user", "content": "Hello, Claude" }]
|
|
68
|
+
\`\`\`
|
|
69
|
+
|
|
70
|
+
Example with multiple conversational turns:
|
|
71
|
+
|
|
72
|
+
\`\`\`json
|
|
73
|
+
[
|
|
74
|
+
{ "role": "user", "content": "Hello there." },
|
|
75
|
+
{ "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
|
|
76
|
+
{ "role": "user", "content": "Can you explain LLMs in plain English?" }
|
|
77
|
+
]
|
|
78
|
+
\`\`\`
|
|
79
|
+
|
|
80
|
+
Example with a partially-filled response from Claude:
|
|
81
|
+
|
|
82
|
+
\`\`\`json
|
|
83
|
+
[
|
|
84
|
+
{
|
|
85
|
+
"role": "user",
|
|
86
|
+
"content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
|
|
87
|
+
},
|
|
88
|
+
{ "role": "assistant", "content": "The best answer is (" }
|
|
89
|
+
]
|
|
90
|
+
\`\`\`
|
|
91
|
+
|
|
92
|
+
Each input message \`content\` may be either a single \`string\` or an array of
|
|
93
|
+
content blocks, where each block has a specific \`type\`. Using a \`string\` for
|
|
94
|
+
\`content\` is shorthand for an array of one content block of type \`"text"\`. The
|
|
95
|
+
following input messages are equivalent:
|
|
96
|
+
|
|
97
|
+
\`\`\`json
|
|
98
|
+
{ "role": "user", "content": "Hello, Claude" }
|
|
99
|
+
\`\`\`
|
|
100
|
+
|
|
101
|
+
\`\`\`json
|
|
102
|
+
{ "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
|
|
103
|
+
\`\`\`
|
|
104
|
+
|
|
105
|
+
Starting with Claude 3 models, you can also send image content blocks:
|
|
106
|
+
|
|
107
|
+
\`\`\`json
|
|
108
|
+
{
|
|
109
|
+
"role": "user",
|
|
110
|
+
"content": [
|
|
111
|
+
{
|
|
112
|
+
"type": "image",
|
|
113
|
+
"source": {
|
|
114
|
+
"type": "base64",
|
|
115
|
+
"media_type": "image/jpeg",
|
|
116
|
+
"data": "/9j/4AAQSkZJRg..."
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
{ "type": "text", "text": "What is in this image?" }
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
\`\`\`
|
|
123
|
+
|
|
124
|
+
We currently support the \`base64\` source type for images, and the \`image/jpeg\`,
|
|
125
|
+
\`image/png\`, \`image/gif\`, and \`image/webp\` media types.
|
|
126
|
+
|
|
127
|
+
See [examples](https://docs.anthropic.com/en/api/messages-examples) for more
|
|
128
|
+
input examples.
|
|
129
|
+
|
|
130
|
+
Note that if you want to include a
|
|
131
|
+
[system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
|
|
132
|
+
the top-level \`system\` parameter — there is no \`"system"\` role for input
|
|
133
|
+
messages in the Messages API.
|
|
134
|
+
`,
|
|
135
|
+
},
|
|
136
|
+
max_tokens: {
|
|
137
|
+
type: 'integer',
|
|
138
|
+
description: `The maximum number of tokens to generate before stopping.
|
|
139
|
+
|
|
140
|
+
Note that our models may stop _before_ reaching this maximum. This parameter
|
|
141
|
+
only specifies the absolute maximum number of tokens to generate.
|
|
142
|
+
|
|
143
|
+
Different models have different maximum values for this parameter. See
|
|
144
|
+
[models](https://docs.anthropic.com/en/docs/models-overview) for details.
|
|
145
|
+
`,
|
|
146
|
+
},
|
|
147
|
+
metadata: {
|
|
148
|
+
$ref: '#/components/schemas/CreateMessageRequestMetadata',
|
|
149
|
+
},
|
|
150
|
+
stop_sequences: {
|
|
151
|
+
type: 'array',
|
|
152
|
+
items: {
|
|
153
|
+
type: 'string',
|
|
154
|
+
},
|
|
155
|
+
description: `Custom text sequences that will cause the model to stop generating.
|
|
156
|
+
|
|
157
|
+
Our models will normally stop when they have naturally completed their turn,
|
|
158
|
+
which will result in a response \`stop_reason\` of \`"end_turn"\`.
|
|
159
|
+
|
|
160
|
+
If you want the model to stop generating when it encounters custom strings of
|
|
161
|
+
text, you can use the \`stop_sequences\` parameter. If the model encounters one of
|
|
162
|
+
the custom sequences, the response \`stop_reason\` value will be \`"stop_sequence"\`
|
|
163
|
+
and the response \`stop_sequence\` value will contain the matched stop sequence.
|
|
164
|
+
`,
|
|
165
|
+
},
|
|
166
|
+
system: {
|
|
167
|
+
type: 'string',
|
|
168
|
+
oneOf: [
|
|
169
|
+
{
|
|
170
|
+
type: 'string',
|
|
171
|
+
description: 'A single text block.',
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
type: 'array',
|
|
175
|
+
items: {
|
|
176
|
+
$ref: '#/components/schemas/Block',
|
|
177
|
+
},
|
|
178
|
+
description: 'An array of content blocks.',
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
description: `System prompt.
|
|
182
|
+
|
|
183
|
+
A system prompt is a way of providing context and instructions to Claude, such
|
|
184
|
+
as specifying a particular goal or role. See our
|
|
185
|
+
[guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
|
|
186
|
+
`,
|
|
187
|
+
},
|
|
188
|
+
temperature: {
|
|
189
|
+
type: 'number',
|
|
190
|
+
description: `Amount of randomness injected into the response.
|
|
191
|
+
|
|
192
|
+
Defaults to \`1.0\`. Ranges from \`0.0\` to \`1.0\`. Use \`temperature\` closer to \`0.0\`
|
|
193
|
+
for analytical / multiple choice, and closer to \`1.0\` for creative and
|
|
194
|
+
generative tasks.
|
|
195
|
+
|
|
196
|
+
Note that even with \`temperature\` of \`0.0\`, the results will not be fully
|
|
197
|
+
deterministic.
|
|
198
|
+
`,
|
|
199
|
+
},
|
|
200
|
+
tool_choice: {
|
|
201
|
+
$ref: '#/components/schemas/ToolChoice',
|
|
202
|
+
},
|
|
203
|
+
tools: {
|
|
204
|
+
type: 'array',
|
|
205
|
+
items: {
|
|
206
|
+
$ref: '#/components/schemas/Tool',
|
|
207
|
+
},
|
|
208
|
+
description: `Definitions of tools that the model may use.
|
|
209
|
+
|
|
210
|
+
If you include \`tools\` in your API request, the model may return \`tool_use\`
|
|
211
|
+
content blocks that represent the model's use of those tools. You can then run
|
|
212
|
+
those tools using the tool input generated by the model and then optionally
|
|
213
|
+
return results back to the model using \`tool_result\` content blocks.
|
|
214
|
+
|
|
215
|
+
Each tool definition includes:
|
|
216
|
+
|
|
217
|
+
- \`name\`: Name of the tool.
|
|
218
|
+
- \`description\`: Optional, but strongly-recommended description of the tool.
|
|
219
|
+
- \`input_schema\`: [JSON schema](https://json-schema.org/) for the tool \`input\`
|
|
220
|
+
shape that the model will produce in \`tool_use\` output content blocks.
|
|
221
|
+
|
|
222
|
+
For example, if you defined \`tools\` as:
|
|
223
|
+
|
|
224
|
+
\`\`\`json
|
|
225
|
+
[
|
|
226
|
+
{
|
|
227
|
+
"name": "get_stock_price",
|
|
228
|
+
"description": "Get the current stock price for a given ticker symbol.",
|
|
229
|
+
"input_schema": {
|
|
230
|
+
"type": "object",
|
|
231
|
+
"properties": {
|
|
232
|
+
"ticker": {
|
|
233
|
+
"type": "string",
|
|
234
|
+
"description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
"required": ["ticker"]
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
]
|
|
241
|
+
\`\`\`
|
|
242
|
+
|
|
243
|
+
And then asked the model "What's the S&P 500 at today?", the model might produce
|
|
244
|
+
\`tool_use\` content blocks in the response like this:
|
|
245
|
+
|
|
246
|
+
\`\`\`json
|
|
247
|
+
[
|
|
248
|
+
{
|
|
249
|
+
"type": "tool_use",
|
|
250
|
+
"id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
|
|
251
|
+
"name": "get_stock_price",
|
|
252
|
+
"input": { "ticker": "^GSPC" }
|
|
253
|
+
}
|
|
254
|
+
]
|
|
255
|
+
\`\`\`
|
|
256
|
+
|
|
257
|
+
You might then run your \`get_stock_price\` tool with \`{"ticker": "^GSPC"}\` as an
|
|
258
|
+
input, and return the following back to the model in a subsequent \`user\`
|
|
259
|
+
message:
|
|
260
|
+
|
|
261
|
+
\`\`\`json
|
|
262
|
+
[
|
|
263
|
+
{
|
|
264
|
+
"type": "tool_result",
|
|
265
|
+
"tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
|
|
266
|
+
"content": "259.75 USD"
|
|
267
|
+
}
|
|
268
|
+
]
|
|
269
|
+
\`\`\`
|
|
270
|
+
|
|
271
|
+
Tools can be used for workflows that include running client-side tools and
|
|
272
|
+
functions, or more generally whenever you want the model to produce a particular
|
|
273
|
+
JSON structure of output.
|
|
274
|
+
|
|
275
|
+
See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
|
|
276
|
+
`,
|
|
277
|
+
},
|
|
278
|
+
top_k: {
|
|
279
|
+
type: 'integer',
|
|
280
|
+
description: `Only sample from the top K options for each subsequent token.
|
|
281
|
+
|
|
282
|
+
Used to remove "long tail" low probability responses.
|
|
283
|
+
[Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
|
|
284
|
+
|
|
285
|
+
Recommended for advanced use cases only. You usually only need to use
|
|
286
|
+
\`temperature\`.
|
|
287
|
+
`,
|
|
288
|
+
},
|
|
289
|
+
top_p: {
|
|
290
|
+
type: 'number',
|
|
291
|
+
description: `Use nucleus sampling.
|
|
292
|
+
|
|
293
|
+
In nucleus sampling, we compute the cumulative distribution over all the options
|
|
294
|
+
for each subsequent token in decreasing probability order and cut it off once it
|
|
295
|
+
reaches a particular probability specified by \`top_p\`. You should either alter
|
|
296
|
+
\`temperature\` or \`top_p\`, but not both.
|
|
297
|
+
|
|
298
|
+
Recommended for advanced use cases only. You usually only need to use
|
|
299
|
+
\`temperature\`.
|
|
300
|
+
`,
|
|
301
|
+
},
|
|
302
|
+
stream: {
|
|
303
|
+
type: 'boolean',
|
|
304
|
+
description: `Whether to incrementally stream the response using server-sent events.
|
|
305
|
+
|
|
306
|
+
See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
|
|
307
|
+
details.
|
|
308
|
+
`,
|
|
309
|
+
default: false,
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
description: 'The request parameters for creating a message.',
|
|
313
|
+
} as const;
|
|
314
|
+
|
|
315
|
+
export const CreateMessageRequestMetadataSchema = {
|
|
316
|
+
type: 'object',
|
|
317
|
+
properties: {
|
|
318
|
+
user_id: {
|
|
319
|
+
type: 'string',
|
|
320
|
+
description: `An external identifier for the user who is associated with the request.
|
|
321
|
+
|
|
322
|
+
This should be a uuid, hash value, or other opaque identifier. Anthropic may use
|
|
323
|
+
this id to help detect abuse. Do not include any identifying information such as
|
|
324
|
+
name, email address, or phone number.
|
|
325
|
+
`,
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
description: 'An object describing metadata about the request.',
|
|
329
|
+
} as const;
|
|
330
|
+
|
|
331
|
+
export const ToolChoiceSchema = {
|
|
332
|
+
required: ['type'],
|
|
333
|
+
type: 'object',
|
|
334
|
+
properties: {
|
|
335
|
+
type: {
|
|
336
|
+
$ref: '#/components/schemas/ToolChoiceType',
|
|
337
|
+
},
|
|
338
|
+
name: {
|
|
339
|
+
type: 'string',
|
|
340
|
+
description: 'The name of the tool to use.',
|
|
341
|
+
},
|
|
342
|
+
disable_parallel_tool_use: {
|
|
343
|
+
type: 'boolean',
|
|
344
|
+
description: 'Whether to disable parallel tool use.',
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
description: `How the model should use the provided tools. The model can use a specific tool,
|
|
348
|
+
any available tool, or decide by itself.
|
|
349
|
+
|
|
350
|
+
- \`auto\`: allows Claude to decide whether to call any provided tools or not. This is the default value.
|
|
351
|
+
- \`any\`: tells Claude that it must use one of the provided tools, but doesn’t force a particular tool.
|
|
352
|
+
- \`tool\`: allows us to force Claude to always use a particular tool specified in the \`name\` field.
|
|
353
|
+
`,
|
|
354
|
+
} as const;
|
|
355
|
+
|
|
356
|
+
export const ToolChoiceTypeSchema = {
|
|
357
|
+
enum: ['auto', 'any', 'tool'],
|
|
358
|
+
type: 'string',
|
|
359
|
+
description: `How the model should use the provided tools. The model can use a specific tool,
|
|
360
|
+
any available tool, or decide by itself.
|
|
361
|
+
|
|
362
|
+
- \`auto\`: allows Claude to decide whether to call any provided tools or not. This is the default value.
|
|
363
|
+
- \`any\`: tells Claude that it must use one of the provided tools, but doesn't force a particular tool.
|
|
364
|
+
- \`tool\`: allows us to force Claude to always use a particular tool specified in the \`name\` field.
|
|
365
|
+
`,
|
|
366
|
+
} as const;
|
|
367
|
+
|
|
368
|
+
export const MessageSchema = {
|
|
369
|
+
required: ['content', 'role'],
|
|
370
|
+
type: 'object',
|
|
371
|
+
properties: {
|
|
372
|
+
id: {
|
|
373
|
+
type: 'string',
|
|
374
|
+
description: `Unique object identifier.
|
|
375
|
+
|
|
376
|
+
The format and length of IDs may change over time.
|
|
377
|
+
`,
|
|
378
|
+
},
|
|
379
|
+
content: {
|
|
380
|
+
oneOf: [
|
|
381
|
+
{
|
|
382
|
+
type: 'string',
|
|
383
|
+
description: 'A single text block.',
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
type: 'array',
|
|
387
|
+
items: {
|
|
388
|
+
$ref: '#/components/schemas/Block',
|
|
389
|
+
},
|
|
390
|
+
description: 'An array of content blocks.',
|
|
391
|
+
},
|
|
392
|
+
],
|
|
393
|
+
description: 'The content of the message.',
|
|
394
|
+
},
|
|
395
|
+
role: {
|
|
396
|
+
$ref: '#/components/schemas/MessageRole',
|
|
397
|
+
},
|
|
398
|
+
model: {
|
|
399
|
+
type: 'string',
|
|
400
|
+
description: 'The model that handled the request.',
|
|
401
|
+
},
|
|
402
|
+
stop_reason: {
|
|
403
|
+
$ref: '#/components/schemas/StopReason',
|
|
404
|
+
},
|
|
405
|
+
stop_sequence: {
|
|
406
|
+
type: 'string',
|
|
407
|
+
description: `Which custom stop sequence was generated, if any.
|
|
408
|
+
|
|
409
|
+
This value will be a non-null string if one of your custom stop sequences was
|
|
410
|
+
generated.
|
|
411
|
+
`,
|
|
412
|
+
},
|
|
413
|
+
type: {
|
|
414
|
+
type: 'string',
|
|
415
|
+
description: `Object type.
|
|
416
|
+
|
|
417
|
+
For Messages, this is always \`"message"\`.
|
|
418
|
+
`,
|
|
419
|
+
},
|
|
420
|
+
usage: {
|
|
421
|
+
$ref: '#/components/schemas/Usage',
|
|
422
|
+
},
|
|
423
|
+
},
|
|
424
|
+
description: 'A message in a chat conversation.',
|
|
425
|
+
} as const;
|
|
426
|
+
|
|
427
|
+
export const MessageRoleSchema = {
|
|
428
|
+
enum: ['user', 'assistant'],
|
|
429
|
+
type: 'string',
|
|
430
|
+
description: 'The role of the messages author.',
|
|
431
|
+
} as const;
|
|
432
|
+
|
|
433
|
+
export const ToolSchema = {
|
|
434
|
+
oneOf: [
|
|
435
|
+
{
|
|
436
|
+
$ref: '#/components/schemas/ToolCustom',
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
$ref: '#/components/schemas/ToolComputerUse',
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
$ref: '#/components/schemas/ToolTextEditor',
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
$ref: '#/components/schemas/ToolBash',
|
|
446
|
+
},
|
|
447
|
+
],
|
|
448
|
+
description: 'A tool the model may use.',
|
|
449
|
+
discriminator: {
|
|
450
|
+
propertyName: 'type',
|
|
451
|
+
},
|
|
452
|
+
} as const;
|
|
453
|
+
|
|
454
|
+
export const ToolCustomSchema = {
|
|
455
|
+
required: ['name', 'input_schema'],
|
|
456
|
+
type: 'object',
|
|
457
|
+
properties: {
|
|
458
|
+
type: {
|
|
459
|
+
type: 'string',
|
|
460
|
+
description: 'The type of tool.',
|
|
461
|
+
default: null,
|
|
462
|
+
},
|
|
463
|
+
name: {
|
|
464
|
+
type: 'string',
|
|
465
|
+
description: 'The name of the tool. Must match the regex `^[a-zA-Z0-9_-]{1,64}$`.',
|
|
466
|
+
},
|
|
467
|
+
description: {
|
|
468
|
+
type: 'string',
|
|
469
|
+
description: `Description of what this tool does.
|
|
470
|
+
|
|
471
|
+
Tool descriptions should be as detailed as possible. The more information that
|
|
472
|
+
the model has about what the tool is and how to use it, the better it will
|
|
473
|
+
perform. You can use natural language descriptions to reinforce important
|
|
474
|
+
aspects of the tool input JSON schema.
|
|
475
|
+
`,
|
|
476
|
+
},
|
|
477
|
+
input_schema: {
|
|
478
|
+
type: 'object',
|
|
479
|
+
description: `[JSON schema](https://json-schema.org/) for this tool's input.
|
|
480
|
+
|
|
481
|
+
This defines the shape of the \`input\` that your tool accepts and that the model
|
|
482
|
+
will produce.
|
|
483
|
+
`,
|
|
484
|
+
},
|
|
485
|
+
},
|
|
486
|
+
description: 'A custom tool the model may use.',
|
|
487
|
+
} as const;
|
|
488
|
+
|
|
489
|
+
export const ToolComputerUseSchema = {
|
|
490
|
+
required: ['display_width_px', 'display_height_px'],
|
|
491
|
+
type: 'object',
|
|
492
|
+
properties: {
|
|
493
|
+
type: {
|
|
494
|
+
type: 'string',
|
|
495
|
+
description: 'The type of tool.',
|
|
496
|
+
default: 'computer_20241022',
|
|
497
|
+
},
|
|
498
|
+
name: {
|
|
499
|
+
type: 'string',
|
|
500
|
+
description: 'The name of the tool.',
|
|
501
|
+
default: 'computer',
|
|
502
|
+
},
|
|
503
|
+
cache_control: {
|
|
504
|
+
$ref: '#/components/schemas/CacheControlEphemeral',
|
|
505
|
+
},
|
|
506
|
+
display_width_px: {
|
|
507
|
+
type: 'integer',
|
|
508
|
+
description: 'The width of the display in pixels.',
|
|
509
|
+
},
|
|
510
|
+
display_height_px: {
|
|
511
|
+
type: 'integer',
|
|
512
|
+
description: 'The height of the display in pixels.',
|
|
513
|
+
},
|
|
514
|
+
display_number: {
|
|
515
|
+
type: 'integer',
|
|
516
|
+
description: 'The number of the display to use.',
|
|
517
|
+
nullable: true,
|
|
518
|
+
},
|
|
519
|
+
},
|
|
520
|
+
description: 'A tool that uses a mouse and keyboard to interact with a computer, and take screenshots.',
|
|
521
|
+
} as const;
|
|
522
|
+
|
|
523
|
+
export const ToolTextEditorSchema = {
|
|
524
|
+
type: 'object',
|
|
525
|
+
properties: {
|
|
526
|
+
type: {
|
|
527
|
+
type: 'string',
|
|
528
|
+
description: 'The type of tool.',
|
|
529
|
+
default: 'text_editor_20241022',
|
|
530
|
+
},
|
|
531
|
+
name: {
|
|
532
|
+
type: 'string',
|
|
533
|
+
description: 'The name of the tool.',
|
|
534
|
+
default: 'str_replace_editor',
|
|
535
|
+
},
|
|
536
|
+
cache_control: {
|
|
537
|
+
$ref: '#/components/schemas/CacheControlEphemeral',
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
description: 'A tool for viewing, creating and editing files.',
|
|
541
|
+
} as const;
|
|
542
|
+
|
|
543
|
+
export const ToolBashSchema = {
|
|
544
|
+
type: 'object',
|
|
545
|
+
properties: {
|
|
546
|
+
type: {
|
|
547
|
+
type: 'string',
|
|
548
|
+
description: 'The type of tool.',
|
|
549
|
+
default: 'bash_20241022',
|
|
550
|
+
},
|
|
551
|
+
name: {
|
|
552
|
+
type: 'string',
|
|
553
|
+
description: 'The name of the tool.',
|
|
554
|
+
default: 'bash',
|
|
555
|
+
},
|
|
556
|
+
cache_control: {
|
|
557
|
+
$ref: '#/components/schemas/CacheControlEphemeral',
|
|
558
|
+
},
|
|
559
|
+
},
|
|
560
|
+
description: 'A tool for running commands in a bash shell.',
|
|
561
|
+
} as const;
|
|
562
|
+
|
|
563
|
+
export const BlockSchema = {
|
|
564
|
+
oneOf: [
|
|
565
|
+
{
|
|
566
|
+
$ref: '#/components/schemas/TextBlock',
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
$ref: '#/components/schemas/ImageBlock',
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
$ref: '#/components/schemas/ToolUseBlock',
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
$ref: '#/components/schemas/ToolResultBlock',
|
|
576
|
+
},
|
|
577
|
+
],
|
|
578
|
+
description: 'A block of content in a message.',
|
|
579
|
+
discriminator: {
|
|
580
|
+
propertyName: 'type',
|
|
581
|
+
mapping: {
|
|
582
|
+
text: '#/components/schemas/TextBlock',
|
|
583
|
+
image: '#/components/schemas/ImageBlock',
|
|
584
|
+
tool_use: '#/components/schemas/ToolUseBlock',
|
|
585
|
+
tool_result: '#/components/schemas/ToolResultBlock',
|
|
586
|
+
},
|
|
587
|
+
},
|
|
588
|
+
} as const;
|
|
589
|
+
|
|
590
|
+
export const TextBlockSchema = {
|
|
591
|
+
required: ['text'],
|
|
592
|
+
type: 'object',
|
|
593
|
+
properties: {
|
|
594
|
+
text: {
|
|
595
|
+
type: 'string',
|
|
596
|
+
description: 'The text content.',
|
|
597
|
+
},
|
|
598
|
+
type: {
|
|
599
|
+
type: 'string',
|
|
600
|
+
description: 'The type of content block.',
|
|
601
|
+
default: 'text',
|
|
602
|
+
},
|
|
603
|
+
cache_control: {
|
|
604
|
+
$ref: '#/components/schemas/CacheControlEphemeral',
|
|
605
|
+
},
|
|
606
|
+
},
|
|
607
|
+
description: 'A block of text content.',
|
|
608
|
+
} as const;
|
|
609
|
+
|
|
610
|
+
export const ImageBlockSchema = {
|
|
611
|
+
required: ['source'],
|
|
612
|
+
type: 'object',
|
|
613
|
+
properties: {
|
|
614
|
+
source: {
|
|
615
|
+
$ref: '#/components/schemas/ImageBlockSource',
|
|
616
|
+
},
|
|
617
|
+
type: {
|
|
618
|
+
type: 'string',
|
|
619
|
+
description: 'The type of content block.',
|
|
620
|
+
default: 'image',
|
|
621
|
+
},
|
|
622
|
+
cache_control: {
|
|
623
|
+
$ref: '#/components/schemas/CacheControlEphemeral',
|
|
624
|
+
},
|
|
625
|
+
},
|
|
626
|
+
description: 'A block of image content.',
|
|
627
|
+
} as const;
|
|
628
|
+
|
|
629
|
+
export const ImageBlockSourceSchema = {
|
|
630
|
+
required: ['data', 'media_type', 'type'],
|
|
631
|
+
type: 'object',
|
|
632
|
+
properties: {
|
|
633
|
+
data: {
|
|
634
|
+
type: 'string',
|
|
635
|
+
description: 'The base64-encoded image data.',
|
|
636
|
+
},
|
|
637
|
+
media_type: {
|
|
638
|
+
enum: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],
|
|
639
|
+
type: 'string',
|
|
640
|
+
description: 'The media type of the image.',
|
|
641
|
+
},
|
|
642
|
+
type: {
|
|
643
|
+
enum: ['base64'],
|
|
644
|
+
type: 'string',
|
|
645
|
+
description: 'The type of image source.',
|
|
646
|
+
},
|
|
647
|
+
},
|
|
648
|
+
description: 'The source of an image block.',
|
|
649
|
+
} as const;
|
|
650
|
+
|
|
651
|
+
export const ToolUseBlockSchema = {
|
|
652
|
+
required: ['id', 'name', 'input'],
|
|
653
|
+
type: 'object',
|
|
654
|
+
properties: {
|
|
655
|
+
id: {
|
|
656
|
+
type: 'string',
|
|
657
|
+
description: `A unique identifier for this particular tool use block.
|
|
658
|
+
This will be used to match up the tool results later.
|
|
659
|
+
`,
|
|
660
|
+
example: 'toolu_01A09q90qw90lq917835lq9',
|
|
661
|
+
},
|
|
662
|
+
name: {
|
|
663
|
+
type: 'string',
|
|
664
|
+
description: 'The name of the tool being used.',
|
|
665
|
+
example: 'get_weather',
|
|
666
|
+
},
|
|
667
|
+
input: {
|
|
668
|
+
type: 'object',
|
|
669
|
+
description: "An object containing the input being passed to the tool, conforming to the tool's `input_schema`.",
|
|
670
|
+
},
|
|
671
|
+
type: {
|
|
672
|
+
type: 'string',
|
|
673
|
+
description: 'The type of content block.',
|
|
674
|
+
default: 'tool_use',
|
|
675
|
+
},
|
|
676
|
+
cache_control: {
|
|
677
|
+
$ref: '#/components/schemas/CacheControlEphemeral',
|
|
678
|
+
},
|
|
679
|
+
},
|
|
680
|
+
description: 'The tool the model wants to use.',
|
|
681
|
+
} as const;
|
|
682
|
+
|
|
683
|
+
export const ToolResultBlockSchema = {
|
|
684
|
+
required: ['tool_use_id', 'content'],
|
|
685
|
+
type: 'object',
|
|
686
|
+
properties: {
|
|
687
|
+
tool_use_id: {
|
|
688
|
+
type: 'string',
|
|
689
|
+
description: 'The `id` of the tool use request this is a result for.',
|
|
690
|
+
},
|
|
691
|
+
content: {
|
|
692
|
+
oneOf: [
|
|
693
|
+
{
|
|
694
|
+
type: 'string',
|
|
695
|
+
description: 'A single text block.',
|
|
696
|
+
},
|
|
697
|
+
{
|
|
698
|
+
type: 'array',
|
|
699
|
+
items: {
|
|
700
|
+
$ref: '#/components/schemas/Block',
|
|
701
|
+
},
|
|
702
|
+
description: 'An array of content blocks.',
|
|
703
|
+
},
|
|
704
|
+
],
|
|
705
|
+
description: `The result of the tool, as a string (e.g. \`"content": "15 degrees"\`)
|
|
706
|
+
or list of nested content blocks (e.g. \`"content": [{"type": "text", "text": "15 degrees"}]\`).
|
|
707
|
+
These content blocks can use the text or image types.
|
|
708
|
+
`,
|
|
709
|
+
},
|
|
710
|
+
is_error: {
|
|
711
|
+
type: 'boolean',
|
|
712
|
+
description: 'Set to `true` if the tool execution resulted in an error.',
|
|
713
|
+
},
|
|
714
|
+
type: {
|
|
715
|
+
type: 'string',
|
|
716
|
+
description: 'The type of content block.',
|
|
717
|
+
default: 'tool_result',
|
|
718
|
+
},
|
|
719
|
+
cache_control: {
|
|
720
|
+
$ref: '#/components/schemas/CacheControlEphemeral',
|
|
721
|
+
},
|
|
722
|
+
},
|
|
723
|
+
description: 'The result of using a tool.',
|
|
724
|
+
} as const;
|
|
725
|
+
|
|
726
|
+
export const CacheControlEphemeralSchema = {
|
|
727
|
+
type: 'object',
|
|
728
|
+
properties: {
|
|
729
|
+
type: {
|
|
730
|
+
enum: ['ephemeral'],
|
|
731
|
+
type: 'string',
|
|
732
|
+
default: 'ephemeral',
|
|
733
|
+
},
|
|
734
|
+
},
|
|
735
|
+
description: 'The cache control settings.',
|
|
736
|
+
} as const;
|
|
737
|
+
|
|
738
|
+
export const StopReasonSchema = {
|
|
739
|
+
enum: ['end_turn', 'max_tokens', 'stop_sequence', 'tool_use'],
|
|
740
|
+
type: 'string',
|
|
741
|
+
description: `The reason that we stopped.
|
|
742
|
+
|
|
743
|
+
This may be one the following values:
|
|
744
|
+
|
|
745
|
+
- \`"end_turn"\`: the model reached a natural stopping point
|
|
746
|
+
- \`"max_tokens"\`: we exceeded the requested \`max_tokens\` or the model's maximum
|
|
747
|
+
- \`"stop_sequence"\`: one of your provided custom \`stop_sequences\` was generated
|
|
748
|
+
- \`"tool_use"\`: the model invoked one or more tools
|
|
749
|
+
|
|
750
|
+
In non-streaming mode this value is always non-null. In streaming mode, it is
|
|
751
|
+
null in the \`message_start\` event and non-null otherwise.
|
|
752
|
+
`,
|
|
753
|
+
nullable: true,
|
|
754
|
+
} as const;
|
|
755
|
+
|
|
756
|
+
export const UsageSchema = {
|
|
757
|
+
required: ['input_tokens', 'output_tokens'],
|
|
758
|
+
type: 'object',
|
|
759
|
+
properties: {
|
|
760
|
+
input_tokens: {
|
|
761
|
+
type: 'integer',
|
|
762
|
+
description: 'The number of input tokens which were used.',
|
|
763
|
+
},
|
|
764
|
+
output_tokens: {
|
|
765
|
+
type: 'integer',
|
|
766
|
+
description: 'The number of output tokens which were used.',
|
|
767
|
+
},
|
|
768
|
+
cache_creation_input_tokens: {
|
|
769
|
+
type: 'integer',
|
|
770
|
+
description: 'The number of input tokens read from the cache.',
|
|
771
|
+
},
|
|
772
|
+
cache_read_input_tokens: {
|
|
773
|
+
type: 'integer',
|
|
774
|
+
description: 'The number of input tokens used to create the cache entry.',
|
|
775
|
+
},
|
|
776
|
+
},
|
|
777
|
+
description: `Billing and rate-limit usage.
|
|
778
|
+
|
|
779
|
+
Anthropic's API bills and rate-limits by token counts, as tokens represent the
|
|
780
|
+
underlying cost to our systems.
|
|
781
|
+
|
|
782
|
+
Under the hood, the API transforms requests into a format suitable for the
|
|
783
|
+
model. The model's output then goes through a parsing stage before becoming an
|
|
784
|
+
API response. As a result, the token counts in \`usage\` will not match one-to-one
|
|
785
|
+
with the exact visible content of an API request or response.
|
|
786
|
+
|
|
787
|
+
For example, \`output_tokens\` will be non-zero, even for an empty string response
|
|
788
|
+
from Claude.
|
|
789
|
+
`,
|
|
790
|
+
} as const;
|
|
791
|
+
|
|
792
|
+
export const CreateMessageBatchRequestSchema = {
|
|
793
|
+
required: ['requests'],
|
|
794
|
+
type: 'object',
|
|
795
|
+
properties: {
|
|
796
|
+
requests: {
|
|
797
|
+
type: 'array',
|
|
798
|
+
items: {
|
|
799
|
+
$ref: '#/components/schemas/BatchMessageRequest',
|
|
800
|
+
},
|
|
801
|
+
description: 'List of requests for prompt completion. Each is an individual request to create a Message.',
|
|
802
|
+
},
|
|
803
|
+
},
|
|
804
|
+
description: 'The request parameters for creating a message batch.',
|
|
805
|
+
} as const;
|
|
806
|
+
|
|
807
|
+
export const BatchMessageRequestSchema = {
|
|
808
|
+
required: ['custom_id', 'params'],
|
|
809
|
+
type: 'object',
|
|
810
|
+
properties: {
|
|
811
|
+
custom_id: {
|
|
812
|
+
type: 'string',
|
|
813
|
+
description: `Developer-provided ID created for each request in a Message Batch. Useful for
|
|
814
|
+
matching results to requests, as results may be given out of request order.
|
|
815
|
+
|
|
816
|
+
Must be unique for each request within the Message Batch.
|
|
817
|
+
`,
|
|
818
|
+
},
|
|
819
|
+
params: {
|
|
820
|
+
$ref: '#/components/schemas/CreateMessageRequest',
|
|
821
|
+
},
|
|
822
|
+
},
|
|
823
|
+
description: 'An individual message request within a batch.',
|
|
824
|
+
} as const;
|
|
825
|
+
|
|
826
|
+
export const MessageBatchSchema = {
|
|
827
|
+
required: ['id', 'created_at', 'expires_at', 'processing_status', 'request_counts', 'type'],
|
|
828
|
+
type: 'object',
|
|
829
|
+
properties: {
|
|
830
|
+
id: {
|
|
831
|
+
type: 'string',
|
|
832
|
+
description: 'Unique object identifier for the message batch.',
|
|
833
|
+
},
|
|
834
|
+
created_at: {
|
|
835
|
+
type: 'string',
|
|
836
|
+
description: 'RFC 3339 datetime string representing the time at which the Message Batch was created.',
|
|
837
|
+
format: 'date-time',
|
|
838
|
+
},
|
|
839
|
+
expires_at: {
|
|
840
|
+
type: 'string',
|
|
841
|
+
description:
|
|
842
|
+
'RFC 3339 datetime string representing the time at which the Message Batch will expire and end processing, which is 24 hours after creation.',
|
|
843
|
+
format: 'date-time',
|
|
844
|
+
},
|
|
845
|
+
processing_status: {
|
|
846
|
+
enum: ['in_progress', 'canceling', 'ended'],
|
|
847
|
+
type: 'string',
|
|
848
|
+
description: 'Processing status of the Message Batch.',
|
|
849
|
+
},
|
|
850
|
+
request_counts: {
|
|
851
|
+
$ref: '#/components/schemas/MessageBatchRequestCounts',
|
|
852
|
+
},
|
|
853
|
+
results_url: {
|
|
854
|
+
type: 'string',
|
|
855
|
+
description:
|
|
856
|
+
'URL to a `.jsonl` file containing the results of the Message Batch requests. Specified only once processing ends.',
|
|
857
|
+
nullable: true,
|
|
858
|
+
},
|
|
859
|
+
type: {
|
|
860
|
+
enum: ['message_batch'],
|
|
861
|
+
type: 'string',
|
|
862
|
+
description: 'Object type. For Message Batches, this is always `"message_batch"`.',
|
|
863
|
+
},
|
|
864
|
+
},
|
|
865
|
+
description: 'A batch of message requests.',
|
|
866
|
+
} as const;
|
|
867
|
+
|
|
868
|
+
export const MessageBatchRequestCountsSchema = {
|
|
869
|
+
required: ['processing', 'succeeded', 'errored', 'canceled', 'expired'],
|
|
870
|
+
type: 'object',
|
|
871
|
+
properties: {
|
|
872
|
+
processing: {
|
|
873
|
+
type: 'integer',
|
|
874
|
+
description: 'Number of requests in the Message Batch that are processing.',
|
|
875
|
+
},
|
|
876
|
+
succeeded: {
|
|
877
|
+
type: 'integer',
|
|
878
|
+
description: 'Number of requests in the Message Batch that have completed successfully.',
|
|
879
|
+
},
|
|
880
|
+
errored: {
|
|
881
|
+
type: 'integer',
|
|
882
|
+
description: 'Number of requests in the Message Batch that encountered an error.',
|
|
883
|
+
},
|
|
884
|
+
canceled: {
|
|
885
|
+
type: 'integer',
|
|
886
|
+
description: 'Number of requests in the Message Batch that have been canceled.',
|
|
887
|
+
},
|
|
888
|
+
expired: {
|
|
889
|
+
type: 'integer',
|
|
890
|
+
description: 'Number of requests in the Message Batch that have expired.',
|
|
891
|
+
},
|
|
892
|
+
},
|
|
893
|
+
description: 'Tallies requests within the Message Batch, categorized by their status.',
|
|
894
|
+
} as const;
|
|
895
|
+
|
|
896
|
+
export const MessageStreamEventSchema = {
|
|
897
|
+
type: 'object',
|
|
898
|
+
oneOf: [
|
|
899
|
+
{
|
|
900
|
+
$ref: '#/components/schemas/MessageStartEvent',
|
|
901
|
+
},
|
|
902
|
+
{
|
|
903
|
+
$ref: '#/components/schemas/MessageDeltaEvent',
|
|
904
|
+
},
|
|
905
|
+
{
|
|
906
|
+
$ref: '#/components/schemas/MessageStopEvent',
|
|
907
|
+
},
|
|
908
|
+
{
|
|
909
|
+
$ref: '#/components/schemas/ContentBlockStartEvent',
|
|
910
|
+
},
|
|
911
|
+
{
|
|
912
|
+
$ref: '#/components/schemas/ContentBlockDeltaEvent',
|
|
913
|
+
},
|
|
914
|
+
{
|
|
915
|
+
$ref: '#/components/schemas/ContentBlockStopEvent',
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
$ref: '#/components/schemas/PingEvent',
|
|
919
|
+
},
|
|
920
|
+
{
|
|
921
|
+
$ref: '#/components/schemas/ErrorEvent',
|
|
922
|
+
},
|
|
923
|
+
],
|
|
924
|
+
description: 'A event in a streaming conversation.',
|
|
925
|
+
discriminator: {
|
|
926
|
+
propertyName: 'type',
|
|
927
|
+
mapping: {
|
|
928
|
+
message_start: '#/components/schemas/MessageStartEvent',
|
|
929
|
+
message_delta: '#/components/schemas/MessageDeltaEvent',
|
|
930
|
+
message_stop: '#/components/schemas/MessageStopEvent',
|
|
931
|
+
content_block_start: '#/components/schemas/ContentBlockStartEvent',
|
|
932
|
+
content_block_delta: '#/components/schemas/ContentBlockDeltaEvent',
|
|
933
|
+
content_block_stop: '#/components/schemas/ContentBlockStopEvent',
|
|
934
|
+
ping: '#/components/schemas/PingEvent',
|
|
935
|
+
error: '#/components/schemas/ErrorEvent',
|
|
936
|
+
},
|
|
937
|
+
},
|
|
938
|
+
} as const;
|
|
939
|
+
|
|
940
|
+
export const MessageStreamEventTypeSchema = {
|
|
941
|
+
enum: [
|
|
942
|
+
'message_start',
|
|
943
|
+
'message_delta',
|
|
944
|
+
'message_stop',
|
|
945
|
+
'content_block_start',
|
|
946
|
+
'content_block_delta',
|
|
947
|
+
'content_block_stop',
|
|
948
|
+
'ping',
|
|
949
|
+
'error',
|
|
950
|
+
],
|
|
951
|
+
type: 'string',
|
|
952
|
+
description: 'The type of a streaming event.',
|
|
953
|
+
} as const;
|
|
954
|
+
|
|
955
|
+
export const MessageStartEventSchema = {
|
|
956
|
+
required: ['message', 'type'],
|
|
957
|
+
type: 'object',
|
|
958
|
+
properties: {
|
|
959
|
+
message: {
|
|
960
|
+
$ref: '#/components/schemas/Message',
|
|
961
|
+
},
|
|
962
|
+
type: {
|
|
963
|
+
$ref: '#/components/schemas/MessageStreamEventType',
|
|
964
|
+
},
|
|
965
|
+
},
|
|
966
|
+
description: 'A start event in a streaming conversation.',
|
|
967
|
+
} as const;
|
|
968
|
+
|
|
969
|
+
export const MessageDeltaEventSchema = {
|
|
970
|
+
required: ['delta', 'type', 'usage'],
|
|
971
|
+
type: 'object',
|
|
972
|
+
properties: {
|
|
973
|
+
delta: {
|
|
974
|
+
$ref: '#/components/schemas/MessageDelta',
|
|
975
|
+
},
|
|
976
|
+
type: {
|
|
977
|
+
$ref: '#/components/schemas/MessageStreamEventType',
|
|
978
|
+
},
|
|
979
|
+
usage: {
|
|
980
|
+
$ref: '#/components/schemas/MessageDeltaUsage',
|
|
981
|
+
},
|
|
982
|
+
},
|
|
983
|
+
description: 'A delta event in a streaming conversation.',
|
|
984
|
+
} as const;
|
|
985
|
+
|
|
986
|
+
export const MessageDeltaSchema = {
|
|
987
|
+
type: 'object',
|
|
988
|
+
properties: {
|
|
989
|
+
stop_reason: {
|
|
990
|
+
$ref: '#/components/schemas/StopReason',
|
|
991
|
+
},
|
|
992
|
+
stop_sequence: {
|
|
993
|
+
type: 'string',
|
|
994
|
+
description: `Which custom stop sequence was generated, if any.
|
|
995
|
+
|
|
996
|
+
This value will be a non-null string if one of your custom stop sequences was
|
|
997
|
+
generated.
|
|
998
|
+
`,
|
|
999
|
+
},
|
|
1000
|
+
},
|
|
1001
|
+
description: 'A delta in a streaming message.',
|
|
1002
|
+
} as const;
|
|
1003
|
+
|
|
1004
|
+
export const MessageDeltaUsageSchema = {
|
|
1005
|
+
required: ['output_tokens'],
|
|
1006
|
+
type: 'object',
|
|
1007
|
+
properties: {
|
|
1008
|
+
output_tokens: {
|
|
1009
|
+
type: 'integer',
|
|
1010
|
+
description: 'The cumulative number of output tokens which were used.',
|
|
1011
|
+
},
|
|
1012
|
+
},
|
|
1013
|
+
description: `Billing and rate-limit usage.
|
|
1014
|
+
|
|
1015
|
+
Anthropic's API bills and rate-limits by token counts, as tokens represent the
|
|
1016
|
+
underlying cost to our systems.
|
|
1017
|
+
|
|
1018
|
+
Under the hood, the API transforms requests into a format suitable for the
|
|
1019
|
+
model. The model's output then goes through a parsing stage before becoming an
|
|
1020
|
+
API response. As a result, the token counts in \`usage\` will not match one-to-one
|
|
1021
|
+
with the exact visible content of an API request or response.
|
|
1022
|
+
|
|
1023
|
+
For example, \`output_tokens\` will be non-zero, even for an empty string response
|
|
1024
|
+
from Claude.
|
|
1025
|
+
`,
|
|
1026
|
+
} as const;
|
|
1027
|
+
|
|
1028
|
+
export const MessageStopEventSchema = {
|
|
1029
|
+
required: ['type'],
|
|
1030
|
+
type: 'object',
|
|
1031
|
+
properties: {
|
|
1032
|
+
type: {
|
|
1033
|
+
$ref: '#/components/schemas/MessageStreamEventType',
|
|
1034
|
+
},
|
|
1035
|
+
},
|
|
1036
|
+
description: 'A stop event in a streaming conversation.',
|
|
1037
|
+
} as const;
|
|
1038
|
+
|
|
1039
|
+
export const ContentBlockStartEventSchema = {
|
|
1040
|
+
required: ['content_block', 'index', 'type'],
|
|
1041
|
+
type: 'object',
|
|
1042
|
+
properties: {
|
|
1043
|
+
content_block: {
|
|
1044
|
+
$ref: '#/components/schemas/Block',
|
|
1045
|
+
},
|
|
1046
|
+
index: {
|
|
1047
|
+
type: 'integer',
|
|
1048
|
+
description: 'The index of the content block.',
|
|
1049
|
+
},
|
|
1050
|
+
type: {
|
|
1051
|
+
$ref: '#/components/schemas/MessageStreamEventType',
|
|
1052
|
+
},
|
|
1053
|
+
},
|
|
1054
|
+
description: 'A start event in a streaming content block.',
|
|
1055
|
+
} as const;
|
|
1056
|
+
|
|
1057
|
+
export const ContentBlockDeltaEventSchema = {
|
|
1058
|
+
required: ['delta', 'index', 'type'],
|
|
1059
|
+
type: 'object',
|
|
1060
|
+
properties: {
|
|
1061
|
+
delta: {
|
|
1062
|
+
$ref: '#/components/schemas/BlockDelta',
|
|
1063
|
+
},
|
|
1064
|
+
index: {
|
|
1065
|
+
type: 'integer',
|
|
1066
|
+
description: 'The index of the content block.',
|
|
1067
|
+
},
|
|
1068
|
+
type: {
|
|
1069
|
+
$ref: '#/components/schemas/MessageStreamEventType',
|
|
1070
|
+
},
|
|
1071
|
+
},
|
|
1072
|
+
description: 'A delta event in a streaming content block.',
|
|
1073
|
+
} as const;
|
|
1074
|
+
|
|
1075
|
+
export const BlockDeltaSchema = {
|
|
1076
|
+
oneOf: [
|
|
1077
|
+
{
|
|
1078
|
+
$ref: '#/components/schemas/TextBlockDelta',
|
|
1079
|
+
},
|
|
1080
|
+
{
|
|
1081
|
+
$ref: '#/components/schemas/InputJsonBlockDelta',
|
|
1082
|
+
},
|
|
1083
|
+
],
|
|
1084
|
+
description: 'A delta in a streaming message.',
|
|
1085
|
+
discriminator: {
|
|
1086
|
+
propertyName: 'type',
|
|
1087
|
+
mapping: {
|
|
1088
|
+
text_delta: '#/components/schemas/TextBlockDelta',
|
|
1089
|
+
input_json_delta: '#/components/schemas/InputJsonBlockDelta',
|
|
1090
|
+
},
|
|
1091
|
+
},
|
|
1092
|
+
} as const;
|
|
1093
|
+
|
|
1094
|
+
export const TextBlockDeltaSchema = {
|
|
1095
|
+
required: ['text', 'type'],
|
|
1096
|
+
type: 'object',
|
|
1097
|
+
properties: {
|
|
1098
|
+
text: {
|
|
1099
|
+
type: 'string',
|
|
1100
|
+
description: 'The text delta.',
|
|
1101
|
+
},
|
|
1102
|
+
type: {
|
|
1103
|
+
type: 'string',
|
|
1104
|
+
description: 'The type of content block.',
|
|
1105
|
+
default: 'text_delta',
|
|
1106
|
+
},
|
|
1107
|
+
},
|
|
1108
|
+
description: 'A delta in a streaming text block.',
|
|
1109
|
+
} as const;
|
|
1110
|
+
|
|
1111
|
+
export const InputJsonBlockDeltaSchema = {
|
|
1112
|
+
required: ['text', 'type'],
|
|
1113
|
+
type: 'object',
|
|
1114
|
+
properties: {
|
|
1115
|
+
partial_json: {
|
|
1116
|
+
type: 'string',
|
|
1117
|
+
description: 'The partial JSON delta.',
|
|
1118
|
+
},
|
|
1119
|
+
type: {
|
|
1120
|
+
type: 'string',
|
|
1121
|
+
description: 'The type of content block.',
|
|
1122
|
+
default: 'input_json_delta',
|
|
1123
|
+
},
|
|
1124
|
+
},
|
|
1125
|
+
description: 'A delta in a streaming input JSON.',
|
|
1126
|
+
} as const;
|
|
1127
|
+
|
|
1128
|
+
export const ContentBlockStopEventSchema = {
|
|
1129
|
+
required: ['index', 'type'],
|
|
1130
|
+
type: 'object',
|
|
1131
|
+
properties: {
|
|
1132
|
+
index: {
|
|
1133
|
+
type: 'integer',
|
|
1134
|
+
description: 'The index of the content block.',
|
|
1135
|
+
},
|
|
1136
|
+
type: {
|
|
1137
|
+
$ref: '#/components/schemas/MessageStreamEventType',
|
|
1138
|
+
},
|
|
1139
|
+
},
|
|
1140
|
+
description: 'A stop event in a streaming content block.',
|
|
1141
|
+
} as const;
|
|
1142
|
+
|
|
1143
|
+
export const PingEventSchema = {
|
|
1144
|
+
required: ['type'],
|
|
1145
|
+
type: 'object',
|
|
1146
|
+
properties: {
|
|
1147
|
+
type: {
|
|
1148
|
+
$ref: '#/components/schemas/MessageStreamEventType',
|
|
1149
|
+
},
|
|
1150
|
+
},
|
|
1151
|
+
description: 'A ping event in a streaming conversation.',
|
|
1152
|
+
} as const;
|
|
1153
|
+
|
|
1154
|
+
export const ErrorEventSchema = {
|
|
1155
|
+
required: ['type', 'error'],
|
|
1156
|
+
type: 'object',
|
|
1157
|
+
properties: {
|
|
1158
|
+
type: {
|
|
1159
|
+
$ref: '#/components/schemas/MessageStreamEventType',
|
|
1160
|
+
},
|
|
1161
|
+
error: {
|
|
1162
|
+
$ref: '#/components/schemas/Error',
|
|
1163
|
+
},
|
|
1164
|
+
},
|
|
1165
|
+
description: 'An error event in a streaming conversation.',
|
|
1166
|
+
} as const;
|
|
1167
|
+
|
|
1168
|
+
export const ErrorSchema = {
|
|
1169
|
+
required: ['type', 'message'],
|
|
1170
|
+
type: 'object',
|
|
1171
|
+
properties: {
|
|
1172
|
+
type: {
|
|
1173
|
+
type: 'string',
|
|
1174
|
+
description: 'The type of error.',
|
|
1175
|
+
},
|
|
1176
|
+
message: {
|
|
1177
|
+
type: 'string',
|
|
1178
|
+
description: 'A human-readable error message.',
|
|
1179
|
+
},
|
|
1180
|
+
},
|
|
1181
|
+
description: 'An error object.',
|
|
1182
|
+
} as const;
|