@anthropic-ai/sdk 0.32.0 → 0.33.0

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.
Files changed (129) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +27 -15
  3. package/core.d.ts +12 -8
  4. package/core.d.ts.map +1 -1
  5. package/core.js +20 -14
  6. package/core.js.map +1 -1
  7. package/core.mjs +20 -14
  8. package/core.mjs.map +1 -1
  9. package/error.d.ts +18 -24
  10. package/error.d.ts.map +1 -1
  11. package/error.js +1 -31
  12. package/error.js.map +1 -1
  13. package/error.mjs +1 -31
  14. package/error.mjs.map +1 -1
  15. package/index.d.mts +21 -8
  16. package/index.d.ts +21 -8
  17. package/index.d.ts.map +1 -1
  18. package/index.js +13 -8
  19. package/index.js.map +1 -1
  20. package/index.mjs +9 -6
  21. package/index.mjs.map +1 -1
  22. package/package.json +1 -1
  23. package/resources/beta/beta.d.ts +14 -6
  24. package/resources/beta/beta.d.ts.map +1 -1
  25. package/resources/beta/beta.js +5 -4
  26. package/resources/beta/beta.js.map +1 -1
  27. package/resources/beta/beta.mjs +5 -4
  28. package/resources/beta/beta.mjs.map +1 -1
  29. package/resources/beta/index.d.ts +2 -2
  30. package/resources/beta/index.d.ts.map +1 -1
  31. package/resources/beta/index.js +4 -3
  32. package/resources/beta/index.js.map +1 -1
  33. package/resources/beta/index.mjs +1 -1
  34. package/resources/beta/index.mjs.map +1 -1
  35. package/resources/beta/messages/messages.d.ts +1 -1
  36. package/resources/beta/messages/messages.d.ts.map +1 -1
  37. package/resources/beta/models.d.ts +49 -0
  38. package/resources/beta/models.d.ts.map +1 -0
  39. package/resources/beta/models.js +30 -0
  40. package/resources/beta/models.js.map +1 -0
  41. package/resources/beta/models.mjs +25 -0
  42. package/resources/beta/models.mjs.map +1 -0
  43. package/resources/completions.d.ts +1 -1
  44. package/resources/completions.d.ts.map +1 -1
  45. package/resources/index.d.ts +4 -2
  46. package/resources/index.d.ts.map +1 -1
  47. package/resources/index.js +20 -2
  48. package/resources/index.js.map +1 -1
  49. package/resources/index.mjs +3 -1
  50. package/resources/index.mjs.map +1 -1
  51. package/resources/messages/batches.d.ts +212 -0
  52. package/resources/messages/batches.d.ts.map +1 -0
  53. package/resources/messages/batches.js +71 -0
  54. package/resources/messages/batches.js.map +1 -0
  55. package/resources/messages/batches.mjs +66 -0
  56. package/resources/messages/batches.mjs.map +1 -0
  57. package/resources/messages/index.d.ts +3 -0
  58. package/resources/messages/index.d.ts.map +1 -0
  59. package/resources/messages/index.js +10 -0
  60. package/resources/messages/index.js.map +1 -0
  61. package/resources/{beta/prompt-caching → messages}/index.mjs +1 -1
  62. package/resources/messages/index.mjs.map +1 -0
  63. package/resources/{messages.d.ts → messages/messages.d.ts} +235 -9
  64. package/resources/messages/messages.d.ts.map +1 -0
  65. package/resources/messages/messages.js +76 -0
  66. package/resources/messages/messages.js.map +1 -0
  67. package/resources/{messages.mjs → messages/messages.mjs} +20 -3
  68. package/resources/messages/messages.mjs.map +1 -0
  69. package/resources/models.d.ts +49 -0
  70. package/resources/models.d.ts.map +1 -0
  71. package/resources/models.js +30 -0
  72. package/resources/models.js.map +1 -0
  73. package/resources/models.mjs +25 -0
  74. package/resources/models.mjs.map +1 -0
  75. package/resources/shared.d.ts +42 -0
  76. package/resources/shared.d.ts.map +1 -0
  77. package/resources/shared.js +4 -0
  78. package/resources/shared.js.map +1 -0
  79. package/resources/shared.mjs +3 -0
  80. package/resources/shared.mjs.map +1 -0
  81. package/src/core.ts +52 -32
  82. package/src/error.ts +23 -39
  83. package/src/index.ts +72 -37
  84. package/src/resources/beta/beta.ts +28 -6
  85. package/src/resources/beta/index.ts +3 -1
  86. package/src/resources/beta/messages/messages.ts +1 -1
  87. package/src/resources/beta/models.ts +78 -0
  88. package/src/resources/completions.ts +1 -1
  89. package/src/resources/index.ts +11 -1
  90. package/src/resources/messages/batches.ts +298 -0
  91. package/src/resources/messages/index.ts +63 -0
  92. package/src/resources/{messages.ts → messages/messages.ts} +304 -10
  93. package/src/resources/models.ts +75 -0
  94. package/src/resources/shared.ts +72 -0
  95. package/src/version.ts +1 -1
  96. package/version.d.ts +1 -1
  97. package/version.js +1 -1
  98. package/version.mjs +1 -1
  99. package/lib/PromptCachingBetaMessageStream.d.ts +0 -96
  100. package/lib/PromptCachingBetaMessageStream.d.ts.map +0 -1
  101. package/lib/PromptCachingBetaMessageStream.js +0 -459
  102. package/lib/PromptCachingBetaMessageStream.js.map +0 -1
  103. package/lib/PromptCachingBetaMessageStream.mjs +0 -455
  104. package/lib/PromptCachingBetaMessageStream.mjs.map +0 -1
  105. package/resources/beta/prompt-caching/index.d.ts +0 -3
  106. package/resources/beta/prompt-caching/index.d.ts.map +0 -1
  107. package/resources/beta/prompt-caching/index.js +0 -9
  108. package/resources/beta/prompt-caching/index.js.map +0 -1
  109. package/resources/beta/prompt-caching/index.mjs.map +0 -1
  110. package/resources/beta/prompt-caching/messages.d.ts +0 -518
  111. package/resources/beta/prompt-caching/messages.d.ts.map +0 -1
  112. package/resources/beta/prompt-caching/messages.js +0 -29
  113. package/resources/beta/prompt-caching/messages.js.map +0 -1
  114. package/resources/beta/prompt-caching/messages.mjs +0 -25
  115. package/resources/beta/prompt-caching/messages.mjs.map +0 -1
  116. package/resources/beta/prompt-caching/prompt-caching.d.ts +0 -10
  117. package/resources/beta/prompt-caching/prompt-caching.d.ts.map +0 -1
  118. package/resources/beta/prompt-caching/prompt-caching.js +0 -39
  119. package/resources/beta/prompt-caching/prompt-caching.js.map +0 -1
  120. package/resources/beta/prompt-caching/prompt-caching.mjs +0 -12
  121. package/resources/beta/prompt-caching/prompt-caching.mjs.map +0 -1
  122. package/resources/messages.d.ts.map +0 -1
  123. package/resources/messages.js +0 -36
  124. package/resources/messages.js.map +0 -1
  125. package/resources/messages.mjs.map +0 -1
  126. package/src/lib/PromptCachingBetaMessageStream.ts +0 -579
  127. package/src/resources/beta/prompt-caching/index.ts +0 -20
  128. package/src/resources/beta/prompt-caching/messages.ts +0 -642
  129. package/src/resources/beta/prompt-caching/prompt-caching.ts +0 -47
@@ -1,642 +0,0 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
- import { APIResource } from "../../../resource.js";
4
- import { APIPromise } from "../../../core.js";
5
- import * as Core from "../../../core.js";
6
- import * as PromptCachingMessagesAPI from "./messages.js";
7
- import * as MessagesAPI from "../../messages.js";
8
- import * as BetaAPI from "../beta.js";
9
- import { Stream } from "../../../streaming.js";
10
- import { PromptCachingBetaMessageStream } from "../../../lib/PromptCachingBetaMessageStream.js";
11
-
12
- export class Messages extends APIResource {
13
- /**
14
- * Send a structured list of input messages with text and/or image content, and the
15
- * model will generate the next message in the conversation.
16
- *
17
- * The Messages API can be used for either single queries or stateless multi-turn
18
- * conversations.
19
- */
20
- create(
21
- params: MessageCreateParamsNonStreaming,
22
- options?: Core.RequestOptions,
23
- ): APIPromise<PromptCachingBetaMessage>;
24
- create(
25
- params: MessageCreateParamsStreaming,
26
- options?: Core.RequestOptions,
27
- ): APIPromise<Stream<RawPromptCachingBetaMessageStreamEvent>>;
28
- create(
29
- params: MessageCreateParamsBase,
30
- options?: Core.RequestOptions,
31
- ): APIPromise<Stream<RawPromptCachingBetaMessageStreamEvent> | PromptCachingBetaMessage>;
32
- create(
33
- params: MessageCreateParams,
34
- options?: Core.RequestOptions,
35
- ): APIPromise<PromptCachingBetaMessage> | APIPromise<Stream<RawPromptCachingBetaMessageStreamEvent>> {
36
- const { betas, ...body } = params;
37
- return this._client.post('/v1/messages?beta=prompt_caching', {
38
- body,
39
- timeout: (this._client as any)._options.timeout ?? 600000,
40
- ...options,
41
- headers: {
42
- 'anthropic-beta': [...(betas ?? []), 'prompt-caching-2024-07-31'].toString(),
43
- ...options?.headers,
44
- },
45
- stream: params.stream ?? false,
46
- }) as APIPromise<PromptCachingBetaMessage> | APIPromise<Stream<RawPromptCachingBetaMessageStreamEvent>>;
47
- }
48
-
49
- /**
50
- * Create a Message stream
51
- */
52
- stream(body: MessageStreamParams, options?: Core.RequestOptions): PromptCachingBetaMessageStream {
53
- return PromptCachingBetaMessageStream.createMessage(this, body, options);
54
- }
55
- }
56
-
57
- export type MessageStreamParams = MessageCreateParamsBase;
58
-
59
- export interface PromptCachingBetaCacheControlEphemeral {
60
- type: 'ephemeral';
61
- }
62
-
63
- export interface PromptCachingBetaImageBlockParam {
64
- source: PromptCachingBetaImageBlockParam.Source;
65
-
66
- type: 'image';
67
-
68
- cache_control?: PromptCachingBetaCacheControlEphemeral | null;
69
- }
70
-
71
- export namespace PromptCachingBetaImageBlockParam {
72
- export interface Source {
73
- data: string;
74
-
75
- media_type: 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp';
76
-
77
- type: 'base64';
78
- }
79
- }
80
-
81
- export interface PromptCachingBetaMessage {
82
- /**
83
- * Unique object identifier.
84
- *
85
- * The format and length of IDs may change over time.
86
- */
87
- id: string;
88
-
89
- /**
90
- * Content generated by the model.
91
- *
92
- * This is an array of content blocks, each of which has a `type` that determines
93
- * its shape.
94
- *
95
- * Example:
96
- *
97
- * ```json
98
- * [{ "type": "text", "text": "Hi, I'm Claude." }]
99
- * ```
100
- *
101
- * If the request input `messages` ended with an `assistant` turn, then the
102
- * response `content` will continue directly from that last turn. You can use this
103
- * to constrain the model's output.
104
- *
105
- * For example, if the input `messages` were:
106
- *
107
- * ```json
108
- * [
109
- * {
110
- * "role": "user",
111
- * "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
112
- * },
113
- * { "role": "assistant", "content": "The best answer is (" }
114
- * ]
115
- * ```
116
- *
117
- * Then the response `content` might be:
118
- *
119
- * ```json
120
- * [{ "type": "text", "text": "B)" }]
121
- * ```
122
- */
123
- content: Array<MessagesAPI.ContentBlock>;
124
-
125
- /**
126
- * The model that will complete your prompt.\n\nSee
127
- * [models](https://docs.anthropic.com/en/docs/models-overview) for additional
128
- * details and options.
129
- */
130
- model: MessagesAPI.Model;
131
-
132
- /**
133
- * Conversational role of the generated message.
134
- *
135
- * This will always be `"assistant"`.
136
- */
137
- role: 'assistant';
138
-
139
- /**
140
- * The reason that we stopped.
141
- *
142
- * This may be one the following values:
143
- *
144
- * - `"end_turn"`: the model reached a natural stopping point
145
- * - `"max_tokens"`: we exceeded the requested `max_tokens` or the model's maximum
146
- * - `"stop_sequence"`: one of your provided custom `stop_sequences` was generated
147
- * - `"tool_use"`: the model invoked one or more tools
148
- *
149
- * In non-streaming mode this value is always non-null. In streaming mode, it is
150
- * null in the `message_start` event and non-null otherwise.
151
- */
152
- stop_reason: 'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' | null;
153
-
154
- /**
155
- * Which custom stop sequence was generated, if any.
156
- *
157
- * This value will be a non-null string if one of your custom stop sequences was
158
- * generated.
159
- */
160
- stop_sequence: string | null;
161
-
162
- /**
163
- * Object type.
164
- *
165
- * For Messages, this is always `"message"`.
166
- */
167
- type: 'message';
168
-
169
- /**
170
- * Billing and rate-limit usage.
171
- *
172
- * Anthropic's API bills and rate-limits by token counts, as tokens represent the
173
- * underlying cost to our systems.
174
- *
175
- * Under the hood, the API transforms requests into a format suitable for the
176
- * model. The model's output then goes through a parsing stage before becoming an
177
- * API response. As a result, the token counts in `usage` will not match one-to-one
178
- * with the exact visible content of an API request or response.
179
- *
180
- * For example, `output_tokens` will be non-zero, even for an empty string response
181
- * from Claude.
182
- */
183
- usage: PromptCachingBetaUsage;
184
- }
185
-
186
- export interface PromptCachingBetaMessageParam {
187
- content:
188
- | string
189
- | Array<
190
- | PromptCachingBetaTextBlockParam
191
- | PromptCachingBetaImageBlockParam
192
- | PromptCachingBetaToolUseBlockParam
193
- | PromptCachingBetaToolResultBlockParam
194
- >;
195
-
196
- role: 'user' | 'assistant';
197
- }
198
-
199
- export interface PromptCachingBetaTextBlockParam {
200
- text: string;
201
-
202
- type: 'text';
203
-
204
- cache_control?: PromptCachingBetaCacheControlEphemeral | null;
205
- }
206
-
207
- export interface PromptCachingBetaTool {
208
- /**
209
- * [JSON schema](https://json-schema.org/) for this tool's input.
210
- *
211
- * This defines the shape of the `input` that your tool accepts and that the model
212
- * will produce.
213
- */
214
- input_schema: PromptCachingBetaTool.InputSchema;
215
-
216
- /**
217
- * Name of the tool.
218
- *
219
- * This is how the tool will be called by the model and in tool_use blocks.
220
- */
221
- name: string;
222
-
223
- cache_control?: PromptCachingBetaCacheControlEphemeral | null;
224
-
225
- /**
226
- * Description of what this tool does.
227
- *
228
- * Tool descriptions should be as detailed as possible. The more information that
229
- * the model has about what the tool is and how to use it, the better it will
230
- * perform. You can use natural language descriptions to reinforce important
231
- * aspects of the tool input JSON schema.
232
- */
233
- description?: string;
234
- }
235
-
236
- export namespace PromptCachingBetaTool {
237
- /**
238
- * [JSON schema](https://json-schema.org/) for this tool's input.
239
- *
240
- * This defines the shape of the `input` that your tool accepts and that the model
241
- * will produce.
242
- */
243
- export interface InputSchema {
244
- type: 'object';
245
-
246
- properties?: unknown | null;
247
- [k: string]: unknown;
248
- }
249
- }
250
-
251
- export interface PromptCachingBetaToolResultBlockParam {
252
- tool_use_id: string;
253
-
254
- type: 'tool_result';
255
-
256
- cache_control?: PromptCachingBetaCacheControlEphemeral | null;
257
-
258
- content?: string | Array<PromptCachingBetaTextBlockParam | PromptCachingBetaImageBlockParam>;
259
-
260
- is_error?: boolean;
261
- }
262
-
263
- export interface PromptCachingBetaToolUseBlockParam {
264
- id: string;
265
-
266
- input: unknown;
267
-
268
- name: string;
269
-
270
- type: 'tool_use';
271
-
272
- cache_control?: PromptCachingBetaCacheControlEphemeral | null;
273
- }
274
-
275
- export interface PromptCachingBetaUsage {
276
- /**
277
- * The number of input tokens used to create the cache entry.
278
- */
279
- cache_creation_input_tokens: number | null;
280
-
281
- /**
282
- * The number of input tokens read from the cache.
283
- */
284
- cache_read_input_tokens: number | null;
285
-
286
- /**
287
- * The number of input tokens which were used.
288
- */
289
- input_tokens: number;
290
-
291
- /**
292
- * The number of output tokens which were used.
293
- */
294
- output_tokens: number;
295
- }
296
-
297
- export interface RawPromptCachingBetaMessageStartEvent {
298
- message: PromptCachingBetaMessage;
299
-
300
- type: 'message_start';
301
- }
302
-
303
- export type RawPromptCachingBetaMessageStreamEvent =
304
- | RawPromptCachingBetaMessageStartEvent
305
- | MessagesAPI.RawMessageDeltaEvent
306
- | MessagesAPI.RawMessageStopEvent
307
- | MessagesAPI.RawContentBlockStartEvent
308
- | MessagesAPI.RawContentBlockDeltaEvent
309
- | MessagesAPI.RawContentBlockStopEvent;
310
-
311
- export type MessageCreateParams = MessageCreateParamsNonStreaming | MessageCreateParamsStreaming;
312
-
313
- export interface MessageCreateParamsBase {
314
- /**
315
- * Body param: The maximum number of tokens to generate before stopping.
316
- *
317
- * Note that our models may stop _before_ reaching this maximum. This parameter
318
- * only specifies the absolute maximum number of tokens to generate.
319
- *
320
- * Different models have different maximum values for this parameter. See
321
- * [models](https://docs.anthropic.com/en/docs/models-overview) for details.
322
- */
323
- max_tokens: number;
324
-
325
- /**
326
- * Body param: Input messages.
327
- *
328
- * Our models are trained to operate on alternating `user` and `assistant`
329
- * conversational turns. When creating a new `Message`, you specify the prior
330
- * conversational turns with the `messages` parameter, and the model then generates
331
- * the next `Message` in the conversation. Consecutive `user` or `assistant` turns
332
- * in your request will be combined into a single turn.
333
- *
334
- * Each input message must be an object with a `role` and `content`. You can
335
- * specify a single `user`-role message, or you can include multiple `user` and
336
- * `assistant` messages.
337
- *
338
- * If the final message uses the `assistant` role, the response content will
339
- * continue immediately from the content in that message. This can be used to
340
- * constrain part of the model's response.
341
- *
342
- * Example with a single `user` message:
343
- *
344
- * ```json
345
- * [{ "role": "user", "content": "Hello, Claude" }]
346
- * ```
347
- *
348
- * Example with multiple conversational turns:
349
- *
350
- * ```json
351
- * [
352
- * { "role": "user", "content": "Hello there." },
353
- * { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
354
- * { "role": "user", "content": "Can you explain LLMs in plain English?" }
355
- * ]
356
- * ```
357
- *
358
- * Example with a partially-filled response from Claude:
359
- *
360
- * ```json
361
- * [
362
- * {
363
- * "role": "user",
364
- * "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
365
- * },
366
- * { "role": "assistant", "content": "The best answer is (" }
367
- * ]
368
- * ```
369
- *
370
- * Each input message `content` may be either a single `string` or an array of
371
- * content blocks, where each block has a specific `type`. Using a `string` for
372
- * `content` is shorthand for an array of one content block of type `"text"`. The
373
- * following input messages are equivalent:
374
- *
375
- * ```json
376
- * { "role": "user", "content": "Hello, Claude" }
377
- * ```
378
- *
379
- * ```json
380
- * { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
381
- * ```
382
- *
383
- * Starting with Claude 3 models, you can also send image content blocks:
384
- *
385
- * ```json
386
- * {
387
- * "role": "user",
388
- * "content": [
389
- * {
390
- * "type": "image",
391
- * "source": {
392
- * "type": "base64",
393
- * "media_type": "image/jpeg",
394
- * "data": "/9j/4AAQSkZJRg..."
395
- * }
396
- * },
397
- * { "type": "text", "text": "What is in this image?" }
398
- * ]
399
- * }
400
- * ```
401
- *
402
- * We currently support the `base64` source type for images, and the `image/jpeg`,
403
- * `image/png`, `image/gif`, and `image/webp` media types.
404
- *
405
- * See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
406
- * more input examples.
407
- *
408
- * Note that if you want to include a
409
- * [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
410
- * the top-level `system` parameter — there is no `"system"` role for input
411
- * messages in the Messages API.
412
- */
413
- messages: Array<PromptCachingBetaMessageParam>;
414
-
415
- /**
416
- * Body param: The model that will complete your prompt.\n\nSee
417
- * [models](https://docs.anthropic.com/en/docs/models-overview) for additional
418
- * details and options.
419
- */
420
- model: MessagesAPI.Model;
421
-
422
- /**
423
- * Body param: An object describing metadata about the request.
424
- */
425
- metadata?: MessagesAPI.Metadata;
426
-
427
- /**
428
- * Body param: Custom text sequences that will cause the model to stop generating.
429
- *
430
- * Our models will normally stop when they have naturally completed their turn,
431
- * which will result in a response `stop_reason` of `"end_turn"`.
432
- *
433
- * If you want the model to stop generating when it encounters custom strings of
434
- * text, you can use the `stop_sequences` parameter. If the model encounters one of
435
- * the custom sequences, the response `stop_reason` value will be `"stop_sequence"`
436
- * and the response `stop_sequence` value will contain the matched stop sequence.
437
- */
438
- stop_sequences?: Array<string>;
439
-
440
- /**
441
- * Body param: Whether to incrementally stream the response using server-sent
442
- * events.
443
- *
444
- * See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
445
- * details.
446
- */
447
- stream?: boolean;
448
-
449
- /**
450
- * Body param: System prompt.
451
- *
452
- * A system prompt is a way of providing context and instructions to Claude, such
453
- * as specifying a particular goal or role. See our
454
- * [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
455
- */
456
- system?: string | Array<PromptCachingBetaTextBlockParam>;
457
-
458
- /**
459
- * Body param: Amount of randomness injected into the response.
460
- *
461
- * Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
462
- * for analytical / multiple choice, and closer to `1.0` for creative and
463
- * generative tasks.
464
- *
465
- * Note that even with `temperature` of `0.0`, the results will not be fully
466
- * deterministic.
467
- */
468
- temperature?: number;
469
-
470
- /**
471
- * Body param: How the model should use the provided tools. The model can use a
472
- * specific tool, any available tool, or decide by itself.
473
- */
474
- tool_choice?: MessagesAPI.ToolChoice;
475
-
476
- /**
477
- * Body param: Definitions of tools that the model may use.
478
- *
479
- * If you include `tools` in your API request, the model may return `tool_use`
480
- * content blocks that represent the model's use of those tools. You can then run
481
- * those tools using the tool input generated by the model and then optionally
482
- * return results back to the model using `tool_result` content blocks.
483
- *
484
- * Each tool definition includes:
485
- *
486
- * - `name`: Name of the tool.
487
- * - `description`: Optional, but strongly-recommended description of the tool.
488
- * - `input_schema`: [JSON schema](https://json-schema.org/) for the tool `input`
489
- * shape that the model will produce in `tool_use` output content blocks.
490
- *
491
- * For example, if you defined `tools` as:
492
- *
493
- * ```json
494
- * [
495
- * {
496
- * "name": "get_stock_price",
497
- * "description": "Get the current stock price for a given ticker symbol.",
498
- * "input_schema": {
499
- * "type": "object",
500
- * "properties": {
501
- * "ticker": {
502
- * "type": "string",
503
- * "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
504
- * }
505
- * },
506
- * "required": ["ticker"]
507
- * }
508
- * }
509
- * ]
510
- * ```
511
- *
512
- * And then asked the model "What's the S&P 500 at today?", the model might produce
513
- * `tool_use` content blocks in the response like this:
514
- *
515
- * ```json
516
- * [
517
- * {
518
- * "type": "tool_use",
519
- * "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
520
- * "name": "get_stock_price",
521
- * "input": { "ticker": "^GSPC" }
522
- * }
523
- * ]
524
- * ```
525
- *
526
- * You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
527
- * input, and return the following back to the model in a subsequent `user`
528
- * message:
529
- *
530
- * ```json
531
- * [
532
- * {
533
- * "type": "tool_result",
534
- * "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
535
- * "content": "259.75 USD"
536
- * }
537
- * ]
538
- * ```
539
- *
540
- * Tools can be used for workflows that include running client-side tools and
541
- * functions, or more generally whenever you want the model to produce a particular
542
- * JSON structure of output.
543
- *
544
- * See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
545
- */
546
- tools?: Array<PromptCachingBetaTool>;
547
-
548
- /**
549
- * Body param: Only sample from the top K options for each subsequent token.
550
- *
551
- * Used to remove "long tail" low probability responses.
552
- * [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
553
- *
554
- * Recommended for advanced use cases only. You usually only need to use
555
- * `temperature`.
556
- */
557
- top_k?: number;
558
-
559
- /**
560
- * Body param: Use nucleus sampling.
561
- *
562
- * In nucleus sampling, we compute the cumulative distribution over all the options
563
- * for each subsequent token in decreasing probability order and cut it off once it
564
- * reaches a particular probability specified by `top_p`. You should either alter
565
- * `temperature` or `top_p`, but not both.
566
- *
567
- * Recommended for advanced use cases only. You usually only need to use
568
- * `temperature`.
569
- */
570
- top_p?: number;
571
-
572
- /**
573
- * Header param: Optional header to specify the beta version(s) you want to use.
574
- */
575
- betas?: Array<BetaAPI.AnthropicBeta>;
576
- }
577
-
578
- export namespace MessageCreateParams {
579
- /**
580
- * @deprecated use `Anthropic.Messages.Metadata` instead
581
- */
582
- export type Metadata = MessagesAPI.Metadata;
583
-
584
- /**
585
- * @deprecated use `Anthropic.Messages.ToolChoiceAuto` instead
586
- */
587
- export type ToolChoiceAuto = MessagesAPI.ToolChoiceAuto;
588
-
589
- /**
590
- * @deprecated use `Anthropic.Messages.ToolChoiceAny` instead
591
- */
592
- export type ToolChoiceAny = MessagesAPI.ToolChoiceAny;
593
-
594
- /**
595
- * @deprecated use `Anthropic.Messages.ToolChoiceTool` instead
596
- */
597
- export type ToolChoiceTool = MessagesAPI.ToolChoiceTool;
598
-
599
- export type MessageCreateParamsNonStreaming = PromptCachingMessagesAPI.MessageCreateParamsNonStreaming;
600
- export type MessageCreateParamsStreaming = PromptCachingMessagesAPI.MessageCreateParamsStreaming;
601
- }
602
-
603
- export interface MessageCreateParamsNonStreaming extends MessageCreateParamsBase {
604
- /**
605
- * Body param: Whether to incrementally stream the response using server-sent
606
- * events.
607
- *
608
- * See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
609
- * details.
610
- */
611
- stream?: false;
612
- }
613
-
614
- export interface MessageCreateParamsStreaming extends MessageCreateParamsBase {
615
- /**
616
- * Body param: Whether to incrementally stream the response using server-sent
617
- * events.
618
- *
619
- * See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
620
- * details.
621
- */
622
- stream: true;
623
- }
624
-
625
- export declare namespace Messages {
626
- export {
627
- type PromptCachingBetaCacheControlEphemeral as PromptCachingBetaCacheControlEphemeral,
628
- type PromptCachingBetaImageBlockParam as PromptCachingBetaImageBlockParam,
629
- type PromptCachingBetaMessage as PromptCachingBetaMessage,
630
- type PromptCachingBetaMessageParam as PromptCachingBetaMessageParam,
631
- type PromptCachingBetaTextBlockParam as PromptCachingBetaTextBlockParam,
632
- type PromptCachingBetaTool as PromptCachingBetaTool,
633
- type PromptCachingBetaToolResultBlockParam as PromptCachingBetaToolResultBlockParam,
634
- type PromptCachingBetaToolUseBlockParam as PromptCachingBetaToolUseBlockParam,
635
- type PromptCachingBetaUsage as PromptCachingBetaUsage,
636
- type RawPromptCachingBetaMessageStartEvent as RawPromptCachingBetaMessageStartEvent,
637
- type RawPromptCachingBetaMessageStreamEvent as RawPromptCachingBetaMessageStreamEvent,
638
- type MessageCreateParams as MessageCreateParams,
639
- type MessageCreateParamsNonStreaming as MessageCreateParamsNonStreaming,
640
- type MessageCreateParamsStreaming as MessageCreateParamsStreaming,
641
- };
642
- }
@@ -1,47 +0,0 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
- import { APIResource } from "../../../resource.js";
4
- import * as MessagesAPI from "./messages.js";
5
- import {
6
- MessageCreateParams,
7
- MessageCreateParamsNonStreaming,
8
- MessageCreateParamsStreaming,
9
- Messages,
10
- PromptCachingBetaCacheControlEphemeral,
11
- PromptCachingBetaImageBlockParam,
12
- PromptCachingBetaMessage,
13
- PromptCachingBetaMessageParam,
14
- PromptCachingBetaTextBlockParam,
15
- PromptCachingBetaTool,
16
- PromptCachingBetaToolResultBlockParam,
17
- PromptCachingBetaToolUseBlockParam,
18
- PromptCachingBetaUsage,
19
- RawPromptCachingBetaMessageStartEvent,
20
- RawPromptCachingBetaMessageStreamEvent,
21
- } from "./messages.js";
22
-
23
- export class PromptCaching extends APIResource {
24
- messages: MessagesAPI.Messages = new MessagesAPI.Messages(this._client);
25
- }
26
-
27
- PromptCaching.Messages = Messages;
28
-
29
- export declare namespace PromptCaching {
30
- export {
31
- Messages as Messages,
32
- type PromptCachingBetaCacheControlEphemeral as PromptCachingBetaCacheControlEphemeral,
33
- type PromptCachingBetaImageBlockParam as PromptCachingBetaImageBlockParam,
34
- type PromptCachingBetaMessage as PromptCachingBetaMessage,
35
- type PromptCachingBetaMessageParam as PromptCachingBetaMessageParam,
36
- type PromptCachingBetaTextBlockParam as PromptCachingBetaTextBlockParam,
37
- type PromptCachingBetaTool as PromptCachingBetaTool,
38
- type PromptCachingBetaToolResultBlockParam as PromptCachingBetaToolResultBlockParam,
39
- type PromptCachingBetaToolUseBlockParam as PromptCachingBetaToolUseBlockParam,
40
- type PromptCachingBetaUsage as PromptCachingBetaUsage,
41
- type RawPromptCachingBetaMessageStartEvent as RawPromptCachingBetaMessageStartEvent,
42
- type RawPromptCachingBetaMessageStreamEvent as RawPromptCachingBetaMessageStreamEvent,
43
- type MessageCreateParams as MessageCreateParams,
44
- type MessageCreateParamsNonStreaming as MessageCreateParamsNonStreaming,
45
- type MessageCreateParamsStreaming as MessageCreateParamsStreaming,
46
- };
47
- }