@effect/ai-anthropic 4.0.0-beta.7 → 4.0.0-beta.71

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 (43) hide show
  1. package/dist/AnthropicClient.d.ts +89 -66
  2. package/dist/AnthropicClient.d.ts.map +1 -1
  3. package/dist/AnthropicClient.js +75 -17
  4. package/dist/AnthropicClient.js.map +1 -1
  5. package/dist/AnthropicConfig.d.ts +68 -10
  6. package/dist/AnthropicConfig.d.ts.map +1 -1
  7. package/dist/AnthropicConfig.js +43 -7
  8. package/dist/AnthropicConfig.js.map +1 -1
  9. package/dist/AnthropicError.d.ts +136 -37
  10. package/dist/AnthropicError.d.ts.map +1 -1
  11. package/dist/AnthropicError.js +1 -1
  12. package/dist/AnthropicLanguageModel.d.ts +384 -71
  13. package/dist/AnthropicLanguageModel.d.ts.map +1 -1
  14. package/dist/AnthropicLanguageModel.js +102 -16
  15. package/dist/AnthropicLanguageModel.js.map +1 -1
  16. package/dist/AnthropicTelemetry.d.ts +42 -15
  17. package/dist/AnthropicTelemetry.d.ts.map +1 -1
  18. package/dist/AnthropicTelemetry.js +44 -8
  19. package/dist/AnthropicTelemetry.js.map +1 -1
  20. package/dist/AnthropicTool.d.ts +1116 -183
  21. package/dist/AnthropicTool.d.ts.map +1 -1
  22. package/dist/AnthropicTool.js +818 -129
  23. package/dist/AnthropicTool.js.map +1 -1
  24. package/dist/Generated.d.ts +11661 -5260
  25. package/dist/Generated.d.ts.map +1 -1
  26. package/dist/Generated.js +2318 -915
  27. package/dist/Generated.js.map +1 -1
  28. package/dist/index.d.ts +8 -29
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +8 -29
  31. package/dist/index.js.map +1 -1
  32. package/dist/internal/errors.js +7 -7
  33. package/dist/internal/errors.js.map +1 -1
  34. package/package.json +3 -3
  35. package/src/AnthropicClient.ts +119 -70
  36. package/src/AnthropicConfig.ts +69 -11
  37. package/src/AnthropicError.ts +138 -37
  38. package/src/AnthropicLanguageModel.ts +405 -38
  39. package/src/AnthropicTelemetry.ts +76 -20
  40. package/src/AnthropicTool.ts +1109 -176
  41. package/src/Generated.ts +3751 -1815
  42. package/src/index.ts +8 -29
  43. package/src/internal/errors.ts +9 -7
@@ -1,18 +1,45 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * The `AnthropicLanguageModel` module provides the Anthropic implementation of
3
+ * Effect AI's `LanguageModel` service. It turns Effect AI prompts, tools, files,
4
+ * reasoning parts, and provider options into Anthropic Messages API requests,
5
+ * and converts Anthropic responses and streams back into Effect AI response
6
+ * parts with Anthropic-specific metadata.
7
+ *
8
+ * **When to use**
9
+ *
10
+ * Use when create an Anthropic-backed model with {@link model}
11
+ * - Build or provide a `LanguageModel.LanguageModel` layer with {@link layer}
12
+ * or {@link make}
13
+ * - Supply default request options through {@link Config}
14
+ * - Override configuration for a scoped operation with {@link withConfigOverride}
15
+ * - Attach Anthropic provider options for prompt caching, document citations,
16
+ * reasoning signatures, MCP metadata, and server-side tools
17
+ *
18
+ * **Gotchas**
19
+ *
20
+ * - Prompt files are translated to Anthropic image or document blocks; only the
21
+ * supported media types can be sent to the provider.
22
+ * - Structured output support depends on the selected Claude model, so this
23
+ * module may use Anthropic's native structured output or fall back to a JSON
24
+ * response tool.
25
+ * - Some features require Anthropic beta headers, which are added
26
+ * automatically from the selected tools, files, and model capabilities.
27
+ *
28
+ * @since 4.0.0
3
29
  */
4
30
  /** @effect-diagnostics preferSchemaOverJson:skip-file */
5
31
  import * as Arr from "effect/Array"
32
+ import * as Context from "effect/Context"
6
33
  import * as DateTime from "effect/DateTime"
7
34
  import * as Effect from "effect/Effect"
8
35
  import * as Encoding from "effect/Encoding"
9
36
  import { dual } from "effect/Function"
10
37
  import * as Layer from "effect/Layer"
38
+ import * as Option from "effect/Option"
11
39
  import * as Predicate from "effect/Predicate"
12
40
  import * as Redactable from "effect/Redactable"
13
41
  import * as Schema from "effect/Schema"
14
42
  import * as SchemaAST from "effect/SchemaAST"
15
- import * as ServiceMap from "effect/ServiceMap"
16
43
  import * as Stream from "effect/Stream"
17
44
  import type { Span } from "effect/Tracer"
18
45
  import type { Mutable, Simplify } from "effect/Types"
@@ -33,10 +60,16 @@ import type * as Generated from "./Generated.ts"
33
60
  import * as InternalUtilities from "./internal/utilities.ts"
34
61
 
35
62
  /**
36
- * The available Anthropic Claude model identifiers.
63
+ * Known Anthropic Claude model identifiers exposed by the generated Anthropic schema.
64
+ *
65
+ * **Details**
66
+ *
67
+ * The Anthropic language model constructors accept `Model` values and custom
68
+ * string model ids, so this type is best used for autocomplete and type checking
69
+ * of known Claude ids.
37
70
  *
38
- * @since 1.0.0
39
71
  * @category models
72
+ * @since 4.0.0
40
73
  */
41
74
  export type Model = typeof Generated.Model.Type
42
75
 
@@ -47,13 +80,20 @@ export type Model = typeof Generated.Model.Type
47
80
  /**
48
81
  * Configuration options for the Anthropic language model.
49
82
  *
83
+ * **When to use**
84
+ *
85
+ * Use when you need to provide or override Anthropic model configuration on a
86
+ * per-request basis via `Context.Service`.
87
+ *
88
+ * **Details**
89
+ *
50
90
  * This service can be used to provide default configuration values or to
51
91
  * override configuration on a per-request basis.
52
92
  *
53
- * @since 1.0.0
54
93
  * @category configuration
94
+ * @since 4.0.0
55
95
  */
56
- export class Config extends ServiceMap.Service<
96
+ export class Config extends Context.Service<
57
97
  Config,
58
98
  Simplify<
59
99
  & Partial<
@@ -73,6 +113,8 @@ export class Config extends ServiceMap.Service<
73
113
  /**
74
114
  * Whether to use strict JSON schema validation for tool calls.
75
115
  *
116
+ * **Details**
117
+ *
76
118
  * Only applies to models that support structured outputs. Defaults to
77
119
  * `true` when structured outputs are supported.
78
120
  */
@@ -86,6 +128,17 @@ export class Config extends ServiceMap.Service<
86
128
  // =============================================================================
87
129
 
88
130
  declare module "effect/unstable/ai/Prompt" {
131
+ /**
132
+ * Anthropic-specific options for system messages.
133
+ *
134
+ * **Details**
135
+ *
136
+ * These options are used when translating system messages into Anthropic
137
+ * request content.
138
+ *
139
+ * @category request
140
+ * @since 4.0.0
141
+ */
89
142
  export interface SystemMessageOptions extends ProviderOptions {
90
143
  readonly anthropic?: {
91
144
  /**
@@ -95,6 +148,17 @@ declare module "effect/unstable/ai/Prompt" {
95
148
  } | null
96
149
  }
97
150
 
151
+ /**
152
+ * Anthropic-specific options for user messages.
153
+ *
154
+ * **Details**
155
+ *
156
+ * These options are used when translating user messages into Anthropic
157
+ * request content.
158
+ *
159
+ * @category request
160
+ * @since 4.0.0
161
+ */
98
162
  export interface UserMessageOptions extends ProviderOptions {
99
163
  readonly anthropic?: {
100
164
  /**
@@ -104,6 +168,17 @@ declare module "effect/unstable/ai/Prompt" {
104
168
  } | null
105
169
  }
106
170
 
171
+ /**
172
+ * Anthropic-specific options for assistant messages.
173
+ *
174
+ * **Details**
175
+ *
176
+ * These options are used when replaying assistant messages in Anthropic
177
+ * conversation history.
178
+ *
179
+ * @category request
180
+ * @since 4.0.0
181
+ */
107
182
  export interface AssistantMessageOptions extends ProviderOptions {
108
183
  readonly anthropic?: {
109
184
  /**
@@ -113,6 +188,17 @@ declare module "effect/unstable/ai/Prompt" {
113
188
  } | null
114
189
  }
115
190
 
191
+ /**
192
+ * Anthropic-specific options for tool messages.
193
+ *
194
+ * **Details**
195
+ *
196
+ * These options are used when converting tool results into Anthropic user
197
+ * content blocks.
198
+ *
199
+ * @category request
200
+ * @since 4.0.0
201
+ */
116
202
  export interface ToolMessageOptions extends ProviderOptions {
117
203
  readonly anthropic?: {
118
204
  /**
@@ -122,6 +208,16 @@ declare module "effect/unstable/ai/Prompt" {
122
208
  } | null
123
209
  }
124
210
 
211
+ /**
212
+ * Anthropic-specific options for text prompt parts.
213
+ *
214
+ * **When to use**
215
+ *
216
+ * Use when you use these options to control how text blocks are sent to Anthropic.
217
+ *
218
+ * @category request
219
+ * @since 4.0.0
220
+ */
125
221
  export interface TextPartOptions extends ProviderOptions {
126
222
  readonly anthropic?: {
127
223
  /**
@@ -131,6 +227,17 @@ declare module "effect/unstable/ai/Prompt" {
131
227
  } | null
132
228
  }
133
229
 
230
+ /**
231
+ * Anthropic-specific options for reasoning prompt parts.
232
+ *
233
+ * **Details**
234
+ *
235
+ * Preserves Claude thinking metadata when reasoning content is sent back to
236
+ * Anthropic in later turns.
237
+ *
238
+ * @category request
239
+ * @since 4.0.0
240
+ */
134
241
  export interface ReasoningPartOptions extends ProviderOptions {
135
242
  readonly anthropic?: {
136
243
  readonly info?: {
@@ -155,6 +262,17 @@ declare module "effect/unstable/ai/Prompt" {
155
262
  } | null
156
263
  }
157
264
 
265
+ /**
266
+ * Anthropic-specific options for file prompt parts.
267
+ *
268
+ * **Details**
269
+ *
270
+ * Controls document metadata, citations, and prompt caching for files sent to
271
+ * Anthropic.
272
+ *
273
+ * @category request
274
+ * @since 4.0.0
275
+ */
158
276
  export interface FilePartOptions extends ProviderOptions {
159
277
  readonly anthropic?: {
160
278
  /**
@@ -174,12 +292,25 @@ declare module "effect/unstable/ai/Prompt" {
174
292
  * Additional context about the document that will be forwarded to the
175
293
  * large language model, but will not be used towards cited content.
176
294
  *
177
- * Useful for storing additional document metadata as text or stringified JSON.
295
+ * **When to use**
296
+ *
297
+ * Use when storing additional document metadata as text or stringified JSON.
178
298
  */
179
299
  readonly documentContext?: string | null
180
300
  } | null
181
301
  }
182
302
 
303
+ /**
304
+ * Anthropic-specific options for tool call prompt parts.
305
+ *
306
+ * **Details**
307
+ *
308
+ * Carries Anthropic tool caller metadata, MCP metadata, and cache control for
309
+ * tool use blocks.
310
+ *
311
+ * @category request
312
+ * @since 4.0.0
313
+ */
183
314
  export interface ToolCallPartOptions extends ProviderOptions {
184
315
  readonly anthropic?: {
185
316
  readonly caller?: {
@@ -202,6 +333,16 @@ declare module "effect/unstable/ai/Prompt" {
202
333
  } | null
203
334
  }
204
335
 
336
+ /**
337
+ * Anthropic-specific options for tool result prompt parts.
338
+ *
339
+ * **Details**
340
+ *
341
+ * Controls Anthropic prompt caching for tool result content.
342
+ *
343
+ * @category request
344
+ * @since 4.0.0
345
+ */
205
346
  export interface ToolResultPartOptions extends ProviderOptions {
206
347
  readonly anthropic?: {
207
348
  /**
@@ -211,6 +352,16 @@ declare module "effect/unstable/ai/Prompt" {
211
352
  } | null
212
353
  }
213
354
 
355
+ /**
356
+ * Anthropic-specific options for tool approval request prompt parts.
357
+ *
358
+ * **Details**
359
+ *
360
+ * Controls prompt caching for human approval requests in conversations.
361
+ *
362
+ * @category request
363
+ * @since 4.0.0
364
+ */
214
365
  export interface ToolApprovalRequestPartOptions extends ProviderOptions {
215
366
  readonly anthropic?: {
216
367
  /**
@@ -220,15 +371,16 @@ declare module "effect/unstable/ai/Prompt" {
220
371
  } | null
221
372
  }
222
373
 
223
- export interface ToolApprovalResponsePartOptions extends ProviderOptions {
224
- readonly anthropic?: {
225
- /**
226
- * A breakpoint which marks the end of reusable content eligible for caching.
227
- */
228
- readonly cacheControl?: typeof Generated.CacheControlEphemeral.Encoded | null
229
- } | null
230
- }
231
-
374
+ /**
375
+ * Anthropic-specific options for tool approval response prompt parts.
376
+ *
377
+ * **Details**
378
+ *
379
+ * Controls prompt caching for human approval responses in conversations.
380
+ *
381
+ * @category request
382
+ * @since 4.0.0
383
+ */
232
384
  export interface ToolApprovalResponsePartOptions extends ProviderOptions {
233
385
  readonly anthropic?: {
234
386
  /**
@@ -240,6 +392,17 @@ declare module "effect/unstable/ai/Prompt" {
240
392
  }
241
393
 
242
394
  declare module "effect/unstable/ai/Response" {
395
+ /**
396
+ * Anthropic metadata attached when a reasoning block begins.
397
+ *
398
+ * **Details**
399
+ *
400
+ * Includes Claude thinking metadata needed to continue reasoning-aware
401
+ * conversations.
402
+ *
403
+ * @category response
404
+ * @since 4.0.0
405
+ */
243
406
  export interface ReasoningStartPartMetadata extends ProviderMetadata {
244
407
  readonly anthropic?: {
245
408
  readonly info?: {
@@ -260,6 +423,16 @@ declare module "effect/unstable/ai/Response" {
260
423
  } | null
261
424
  }
262
425
 
426
+ /**
427
+ * Anthropic metadata attached to streaming reasoning deltas.
428
+ *
429
+ * **Details**
430
+ *
431
+ * Includes the signature for streamed Claude thinking content when available.
432
+ *
433
+ * @category response
434
+ * @since 4.0.0
435
+ */
263
436
  export interface ReasoningDeltaPartMetadata extends ProviderMetadata {
264
437
  readonly anthropic?: {
265
438
  readonly info?: {
@@ -273,6 +446,16 @@ declare module "effect/unstable/ai/Response" {
273
446
  } | null
274
447
  }
275
448
 
449
+ /**
450
+ * Anthropic metadata attached to completed reasoning parts.
451
+ *
452
+ * **Details**
453
+ *
454
+ * Preserves Claude thinking or redacted thinking information for later turns.
455
+ *
456
+ * @category response
457
+ * @since 4.0.0
458
+ */
276
459
  export interface ReasoningPartMetadata extends ProviderMetadata {
277
460
  readonly anthropic?: {
278
461
  readonly info?: {
@@ -293,6 +476,17 @@ declare module "effect/unstable/ai/Response" {
293
476
  } | null
294
477
  }
295
478
 
479
+ /**
480
+ * Anthropic metadata attached to tool call response parts.
481
+ *
482
+ * **Details**
483
+ *
484
+ * Identifies Anthropic caller details and MCP tool metadata emitted by the
485
+ * provider.
486
+ *
487
+ * @category response
488
+ * @since 4.0.0
489
+ */
296
490
  export interface ToolCallPartMetadata extends ProviderMetadata {
297
491
  readonly anthropic?: {
298
492
  readonly caller?: {
@@ -311,6 +505,17 @@ declare module "effect/unstable/ai/Response" {
311
505
  } | null
312
506
  }
313
507
 
508
+ /**
509
+ * Anthropic metadata attached to tool result response parts.
510
+ *
511
+ * **Details**
512
+ *
513
+ * Identifies MCP tool metadata associated with provider-executed tool
514
+ * results.
515
+ *
516
+ * @category response
517
+ * @since 4.0.0
518
+ */
314
519
  export interface ToolResultPartMetadata extends ProviderMetadata {
315
520
  readonly anthropic?: {
316
521
  /**
@@ -325,6 +530,16 @@ declare module "effect/unstable/ai/Response" {
325
530
  } | null
326
531
  }
327
532
 
533
+ /**
534
+ * Anthropic metadata for document citations in model responses.
535
+ *
536
+ * **Details**
537
+ *
538
+ * Records the cited document span by character position or page number.
539
+ *
540
+ * @category response
541
+ * @since 4.0.0
542
+ */
328
543
  export interface DocumentSourcePartMetadata extends ProviderMetadata {
329
544
  readonly anthropic?: {
330
545
  readonly source: "document"
@@ -359,6 +574,16 @@ declare module "effect/unstable/ai/Response" {
359
574
  } | null
360
575
  }
361
576
 
577
+ /**
578
+ * Anthropic metadata for URL and web citations in model responses.
579
+ *
580
+ * **Details**
581
+ *
582
+ * Records cited URL text or web-search source freshness information.
583
+ *
584
+ * @category response
585
+ * @since 4.0.0
586
+ */
362
587
  export interface UrlSourcePartMetadata extends ProviderMetadata {
363
588
  readonly anthropic?: {
364
589
  readonly source: "url"
@@ -378,6 +603,17 @@ declare module "effect/unstable/ai/Response" {
378
603
  } | null
379
604
  }
380
605
 
606
+ /**
607
+ * Anthropic metadata attached to the finish part of a response.
608
+ *
609
+ * **Details**
610
+ *
611
+ * Includes container state, context management information, stop details, and
612
+ * token usage reported by Anthropic.
613
+ *
614
+ * @category response
615
+ * @since 4.0.0
616
+ */
381
617
  export interface FinishPartMetadata extends ProviderMetadata {
382
618
  readonly anthropic?: {
383
619
  readonly container: typeof Generated.BetaContainer.Encoded | null
@@ -387,6 +623,16 @@ declare module "effect/unstable/ai/Response" {
387
623
  } | null
388
624
  }
389
625
 
626
+ /**
627
+ * Anthropic metadata attached to error response parts.
628
+ *
629
+ * **Details**
630
+ *
631
+ * Includes the provider request identifier when Anthropic returns one.
632
+ *
633
+ * @category response
634
+ * @since 4.0.0
635
+ */
390
636
  export interface ErrorPartMetadata extends ProviderMetadata {
391
637
  readonly anthropic?: {
392
638
  requestId?: string | null
@@ -399,22 +645,44 @@ declare module "effect/unstable/ai/Response" {
399
645
  // =============================================================================
400
646
 
401
647
  /**
402
- * Creates an Anthropic language model that can be used with `AiModel.provide`.
648
+ * Creates an Anthropic model descriptor that can be provided with `Effect.provide`.
649
+ *
650
+ * **When to use**
651
+ *
652
+ * Use when you want an Anthropic Claude model value that carries provider and
653
+ * model metadata and can be supplied directly to an Effect program.
654
+ *
655
+ * @see {@link layer} for creating a `LanguageModel.LanguageModel` layer directly
656
+ * @see {@link make} for constructing the language model service effectfully
403
657
  *
404
- * @since 1.0.0
405
658
  * @category constructors
659
+ * @since 4.0.0
406
660
  */
407
661
  export const model = (
408
662
  model: (string & {}) | Model,
409
663
  config?: Omit<typeof Config.Service, "model">
410
664
  ): AiModel.Model<"anthropic", LanguageModel.LanguageModel, AnthropicClient> =>
411
- AiModel.make("anthropic", layer({ model, config }))
665
+ AiModel.make("anthropic", model, layer({ model, config }))
412
666
 
413
667
  /**
414
- * Creates an Anthropic language model service.
668
+ * Creates an Anthropic `LanguageModel` service from a model identifier and optional request defaults.
669
+ *
670
+ * **When to use**
671
+ *
672
+ * Use when an Effect needs to construct a `LanguageModel.Service` value backed
673
+ * by `AnthropicClient`.
674
+ *
675
+ * **Details**
676
+ *
677
+ * The returned effect requires `AnthropicClient`. Request defaults from the
678
+ * `config` option are merged with any `Config` service in the context, with
679
+ * context values taking precedence.
680
+ *
681
+ * @see {@link layer} for providing the service as a `Layer`
682
+ * @see {@link model} for creating a model descriptor for `AiModel.provide`
415
683
  *
416
- * @since 1.0.0
417
684
  * @category constructors
685
+ * @since 4.0.0
418
686
  */
419
687
  export const make = Effect.fnUntraced(function*({ model, config: providerConfig }: {
420
688
  readonly model: (string & {}) | Model
@@ -423,7 +691,7 @@ export const make = Effect.fnUntraced(function*({ model, config: providerConfig
423
691
  const client = yield* AnthropicClient
424
692
 
425
693
  const makeConfig: Effect.Effect<typeof Config.Service & { readonly model: string }> = Effect.gen(function*() {
426
- const services = yield* Effect.services<never>()
694
+ const services = yield* Effect.context<never>()
427
695
  return { model, ...providerConfig, ...services.mapUnsafe.get(Config.key) }
428
696
  })
429
697
 
@@ -469,6 +737,7 @@ export const make = Effect.fnUntraced(function*({ model, config: providerConfig
469
737
  )
470
738
 
471
739
  return yield* LanguageModel.make({
740
+ codecTransformer: toCodecAnthropic,
472
741
  generateText: Effect.fnUntraced(function*(options) {
473
742
  const config = yield* makeConfig
474
743
  const toolNameMapper = new Tool.NameMapper(options.tools)
@@ -493,17 +762,23 @@ export const make = Effect.fnUntraced(function*({ model, config: providerConfig
493
762
  return response
494
763
  })
495
764
  ))
496
- }).pipe(Effect.provideService(
497
- LanguageModel.CurrentCodecTransformer,
498
- toCodecAnthropic
499
- ))
765
+ })
500
766
  })
501
767
 
502
768
  /**
503
769
  * Creates a layer for the Anthropic language model.
504
770
  *
505
- * @since 1.0.0
771
+ * **When to use**
772
+ *
773
+ * Use when composing application layers and you want Anthropic to satisfy
774
+ * `LanguageModel.LanguageModel` while supplying `AnthropicClient` from another
775
+ * layer.
776
+ *
777
+ * @see {@link make} for constructing the language model service effectfully
778
+ * @see {@link model} for creating a model service directly
779
+ *
506
780
  * @category layers
781
+ * @since 4.0.0
507
782
  */
508
783
  export const layer = (options: {
509
784
  readonly model: (string & {}) | Model
@@ -514,37 +789,107 @@ export const layer = (options: {
514
789
  /**
515
790
  * Provides config overrides for Anthropic language model operations.
516
791
  *
517
- * @since 1.0.0
792
+ * **When to use**
793
+ *
794
+ * Use to apply Anthropic request configuration to one effect without changing
795
+ * the model's default configuration.
796
+ *
797
+ * **Details**
798
+ *
799
+ * The overrides are merged with any existing `Config` service for the duration
800
+ * of the supplied effect. Fields in `overrides` take precedence over existing
801
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
802
+ * and `withConfigOverride(effect, overrides)`.
803
+ *
804
+ * @see {@link Config} for available Anthropic request configuration fields
805
+ *
518
806
  * @category configuration
807
+ * @since 4.0.0
519
808
  */
520
809
  export const withConfigOverride: {
521
810
  /**
522
811
  * Provides config overrides for Anthropic language model operations.
523
812
  *
524
- * @since 1.0.0
813
+ * **When to use**
814
+ *
815
+ * Use to apply Anthropic request configuration to one effect without changing
816
+ * the model's default configuration.
817
+ *
818
+ * **Details**
819
+ *
820
+ * The overrides are merged with any existing `Config` service for the duration
821
+ * of the supplied effect. Fields in `overrides` take precedence over existing
822
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
823
+ * and `withConfigOverride(effect, overrides)`.
824
+ *
825
+ * @see {@link Config} for available Anthropic request configuration fields
826
+ *
525
827
  * @category configuration
828
+ * @since 4.0.0
526
829
  */
527
830
  (overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>
528
831
  /**
529
832
  * Provides config overrides for Anthropic language model operations.
530
833
  *
531
- * @since 1.0.0
834
+ * **When to use**
835
+ *
836
+ * Use to apply Anthropic request configuration to one effect without changing
837
+ * the model's default configuration.
838
+ *
839
+ * **Details**
840
+ *
841
+ * The overrides are merged with any existing `Config` service for the duration
842
+ * of the supplied effect. Fields in `overrides` take precedence over existing
843
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
844
+ * and `withConfigOverride(effect, overrides)`.
845
+ *
846
+ * @see {@link Config} for available Anthropic request configuration fields
847
+ *
532
848
  * @category configuration
849
+ * @since 4.0.0
533
850
  */
534
851
  <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>
535
852
  } = dual<
536
853
  /**
537
854
  * Provides config overrides for Anthropic language model operations.
538
855
  *
539
- * @since 1.0.0
856
+ * **When to use**
857
+ *
858
+ * Use to apply Anthropic request configuration to one effect without changing
859
+ * the model's default configuration.
860
+ *
861
+ * **Details**
862
+ *
863
+ * The overrides are merged with any existing `Config` service for the duration
864
+ * of the supplied effect. Fields in `overrides` take precedence over existing
865
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
866
+ * and `withConfigOverride(effect, overrides)`.
867
+ *
868
+ * @see {@link Config} for available Anthropic request configuration fields
869
+ *
540
870
  * @category configuration
871
+ * @since 4.0.0
541
872
  */
542
873
  (overrides: typeof Config.Service) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>>,
543
874
  /**
544
875
  * Provides config overrides for Anthropic language model operations.
545
876
  *
546
- * @since 1.0.0
877
+ * **When to use**
878
+ *
879
+ * Use to apply Anthropic request configuration to one effect without changing
880
+ * the model's default configuration.
881
+ *
882
+ * **Details**
883
+ *
884
+ * The overrides are merged with any existing `Config` service for the duration
885
+ * of the supplied effect. Fields in `overrides` take precedence over existing
886
+ * config, and the helper supports both `effect.pipe(withConfigOverride(overrides))`
887
+ * and `withConfigOverride(effect, overrides)`.
888
+ *
889
+ * @see {@link Config} for available Anthropic request configuration fields
890
+ *
547
891
  * @category configuration
892
+ * @since 4.0.0
548
893
  */
549
894
  <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service) => Effect.Effect<A, E, Exclude<R, Config>>
550
895
  >(2, (self, overrides) =>
@@ -962,21 +1307,37 @@ const prepareMessages = Effect.fnUntraced(
962
1307
  // =============================================================================
963
1308
 
964
1309
  /**
965
- * Represents a user-defined tool that can be passed to the Anthropic API.
1310
+ * Encoded Anthropic custom tool definition that can be sent in a Messages API request.
1311
+ *
1312
+ * **When to use**
1313
+ *
1314
+ * Use when you need to type or inspect the provider-specific request payload for
1315
+ * a custom Anthropic tool.
1316
+ *
1317
+ * **Details**
1318
+ *
1319
+ * This type aliases the encoded `Generated.BetaTool` schema used for Effect
1320
+ * user-defined and dynamic tools after conversion. It contains the tool `name`,
1321
+ * optional `description`, and `input_schema`, plus Anthropic-specific fields
1322
+ * such as `strict` and `cache_control`.
1323
+ *
1324
+ * @see {@link AnthropicProviderDefinedTool} for the request shape used by Anthropic built-in provider tools
966
1325
  *
967
- * @since 1.0.0
968
1326
  * @category tools
1327
+ * @since 4.0.0
969
1328
  */
970
1329
  export type AnthropicUserDefinedTool = typeof Generated.BetaTool.Encoded
971
1330
 
972
1331
  /**
973
1332
  * Represents a provider-defined tool that can be passed to the Anthropic API.
974
1333
  *
1334
+ * **Details**
1335
+ *
975
1336
  * These include Anthropic's built-in tools like computer use, code execution,
976
1337
  * web search, and text editing.
977
1338
  *
978
- * @since 1.0.0
979
1339
  * @category tools
1340
+ * @since 4.0.0
980
1341
  */
981
1342
  export type AnthropicProviderDefinedTool =
982
1343
  | typeof Generated.BetaBashTool_20241022.Encoded
@@ -1033,9 +1394,9 @@ const prepareTools = Effect.fnUntraced(
1033
1394
  const providerTools: Array<AnthropicProviderDefinedTool> = []
1034
1395
 
1035
1396
  for (const tool of options.tools) {
1036
- if (Tool.isUserDefined(tool)) {
1397
+ if (Tool.isUserDefined(tool) || Tool.isDynamic(tool)) {
1037
1398
  const description = Tool.getDescription(tool)
1038
- const input_schema = yield* tryJsonSchema(tool.parametersSchema, "prepareTools")
1399
+ const input_schema = yield* tryToolJsonSchema(tool, "prepareTools")
1039
1400
  const toolStrict = Tool.getStrictMode(tool)
1040
1401
  const strict = capabilities.supportsStructuredOutput
1041
1402
  ? (toolStrict ?? config.strictJsonSchema ?? true)
@@ -1248,7 +1609,7 @@ const buildHttpRequestDetails = (
1248
1609
  method: request.method,
1249
1610
  url: request.url,
1250
1611
  urlParams: Array.from(request.urlParams),
1251
- hash: request.hash,
1612
+ hash: Option.getOrUndefined(request.hash),
1252
1613
  headers: Redactable.redact(request.headers) as Record<string, string>
1253
1614
  })
1254
1615
 
@@ -2772,6 +3133,12 @@ const tryJsonSchema = <S extends Schema.Top>(schema: S, method: string) =>
2772
3133
  catch: (error) => unsupportedSchemaError(error, method)
2773
3134
  })
2774
3135
 
3136
+ const tryToolJsonSchema = <T extends Tool.Any | Tool.AnyDynamic>(tool: T, method: string) =>
3137
+ Effect.try({
3138
+ try: () => Tool.getJsonSchema(tool, { transformer: toCodecAnthropic }),
3139
+ catch: (error) => unsupportedSchemaError(error, method)
3140
+ })
3141
+
2775
3142
  const getOutputFormat = Effect.fnUntraced(function*({ capabilities, options }: {
2776
3143
  readonly capabilities: ModelCapabilities
2777
3144
  readonly options: LanguageModel.ProviderOptions