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