@effect/ai-anthropic 0.16.1 → 0.17.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.
- package/AnthropicTool/package.json +6 -0
- package/dist/cjs/AnthropicClient.js +286 -190
- package/dist/cjs/AnthropicClient.js.map +1 -1
- package/dist/cjs/AnthropicLanguageModel.js +1026 -311
- package/dist/cjs/AnthropicLanguageModel.js.map +1 -1
- package/dist/cjs/AnthropicTokenizer.js +8 -6
- package/dist/cjs/AnthropicTokenizer.js.map +1 -1
- package/dist/cjs/AnthropicTool.js +461 -0
- package/dist/cjs/AnthropicTool.js.map +1 -0
- package/dist/cjs/Generated.js +3507 -1230
- package/dist/cjs/Generated.js.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/internal/utilities.js +13 -3
- package/dist/cjs/internal/utilities.js.map +1 -1
- package/dist/dts/AnthropicClient.d.ts +673 -17
- package/dist/dts/AnthropicClient.d.ts.map +1 -1
- package/dist/dts/AnthropicLanguageModel.d.ts +217 -26
- package/dist/dts/AnthropicLanguageModel.d.ts.map +1 -1
- package/dist/dts/AnthropicTokenizer.d.ts +1 -1
- package/dist/dts/AnthropicTokenizer.d.ts.map +1 -1
- package/dist/dts/AnthropicTool.d.ts +523 -0
- package/dist/dts/AnthropicTool.d.ts.map +1 -0
- package/dist/dts/Generated.d.ts +7863 -3496
- package/dist/dts/Generated.d.ts.map +1 -1
- package/dist/dts/index.d.ts +4 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/esm/AnthropicClient.js +269 -188
- package/dist/esm/AnthropicClient.js.map +1 -1
- package/dist/esm/AnthropicLanguageModel.js +1022 -306
- package/dist/esm/AnthropicLanguageModel.js.map +1 -1
- package/dist/esm/AnthropicTokenizer.js +8 -6
- package/dist/esm/AnthropicTokenizer.js.map +1 -1
- package/dist/esm/AnthropicTool.js +452 -0
- package/dist/esm/AnthropicTool.js.map +1 -0
- package/dist/esm/Generated.js +3492 -1063
- package/dist/esm/Generated.js.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/utilities.js +12 -2
- package/dist/esm/internal/utilities.js.map +1 -1
- package/package.json +11 -3
- package/src/AnthropicClient.ts +713 -369
- package/src/AnthropicLanguageModel.ts +1404 -345
- package/src/AnthropicTokenizer.ts +14 -23
- package/src/AnthropicTool.ts +553 -0
- package/src/Generated.ts +4165 -1681
- package/src/index.ts +5 -0
- package/src/internal/utilities.ts +18 -4
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import * as AiError from "@effect/ai/AiError";
|
|
2
5
|
import * as HttpClient from "@effect/platform/HttpClient";
|
|
3
|
-
import type * as HttpClientError from "@effect/platform/HttpClientError";
|
|
4
6
|
import * as HttpClientRequest from "@effect/platform/HttpClientRequest";
|
|
5
7
|
import * as Config from "effect/Config";
|
|
6
8
|
import type { ConfigError } from "effect/ConfigError";
|
|
@@ -8,9 +10,11 @@ import * as Context from "effect/Context";
|
|
|
8
10
|
import * as Effect from "effect/Effect";
|
|
9
11
|
import * as Layer from "effect/Layer";
|
|
10
12
|
import * as Redacted from "effect/Redacted";
|
|
13
|
+
import * as Schema from "effect/Schema";
|
|
14
|
+
import type * as Scope from "effect/Scope";
|
|
11
15
|
import * as Stream from "effect/Stream";
|
|
12
16
|
import * as Generated from "./Generated.js";
|
|
13
|
-
declare const AnthropicClient_base: Context.TagClass<AnthropicClient, "@effect/ai-anthropic/AnthropicClient",
|
|
17
|
+
declare const AnthropicClient_base: Context.TagClass<AnthropicClient, "@effect/ai-anthropic/AnthropicClient", Service>;
|
|
14
18
|
/**
|
|
15
19
|
* @since 1.0.0
|
|
16
20
|
* @category Context
|
|
@@ -18,39 +22,629 @@ declare const AnthropicClient_base: Context.TagClass<AnthropicClient, "@effect/a
|
|
|
18
22
|
export declare class AnthropicClient extends AnthropicClient_base {
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
25
|
+
* Represents the interface that the `AnthropicClient` service provides.
|
|
26
|
+
*
|
|
27
|
+
* This service abstracts the complexity of communicating with Anthropic's API,
|
|
28
|
+
* providing both high-level text generation methods and low-level HTTP access
|
|
29
|
+
* for advanced use cases.
|
|
30
|
+
*
|
|
21
31
|
* @since 1.0.0
|
|
32
|
+
* @category Models
|
|
22
33
|
*/
|
|
23
|
-
export
|
|
34
|
+
export interface Service {
|
|
24
35
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
36
|
+
* The underlying HTTP client capable of communicating with the Anthropic API.
|
|
37
|
+
*
|
|
38
|
+
* This client is pre-configured with authentication, base URL, and standard
|
|
39
|
+
* headers required for Anthropic API communication. It provides direct access
|
|
40
|
+
* to the generated Anthropic API client for operations not covered by the
|
|
41
|
+
* higher-level methods.
|
|
42
|
+
*
|
|
43
|
+
* Use this when you need to:
|
|
44
|
+
* - Access provider-specific API endpoints not available through the AI SDK
|
|
45
|
+
* - Implement custom request/response handling
|
|
46
|
+
* - Use Anthropic API features not yet supported by the Effect AI abstractions
|
|
47
|
+
* - Perform batch operations or non-streaming requests
|
|
48
|
+
*
|
|
49
|
+
* The client automatically handles authentication and follows Anthropic's
|
|
50
|
+
* API conventions for request formatting and error handling.
|
|
27
51
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
readonly
|
|
32
|
-
|
|
52
|
+
readonly client: Generated.Client;
|
|
53
|
+
readonly streamRequest: <A, I, R>(request: HttpClientRequest.HttpClientRequest, schema: Schema.Schema<A, I, R>) => Stream.Stream<A, AiError.AiError, R>;
|
|
54
|
+
readonly createMessage: (options: {
|
|
55
|
+
readonly params?: typeof Generated.BetaMessagesPostParams.Encoded | undefined;
|
|
56
|
+
readonly payload: typeof Generated.BetaCreateMessageParams.Encoded;
|
|
57
|
+
}) => Effect.Effect<Generated.BetaMessage, AiError.AiError>;
|
|
58
|
+
readonly createMessageStream: (options: {
|
|
59
|
+
readonly params?: typeof Generated.BetaMessagesPostParams.Encoded | undefined;
|
|
60
|
+
readonly payload: Omit<typeof Generated.BetaCreateMessageParams.Encoded, "stream">;
|
|
61
|
+
}) => Stream.Stream<MessageStreamEvent, AiError.AiError>;
|
|
33
62
|
}
|
|
34
63
|
/**
|
|
35
64
|
* @since 1.0.0
|
|
36
65
|
* @category Constructors
|
|
37
66
|
*/
|
|
38
67
|
export declare const make: (options: {
|
|
68
|
+
/**
|
|
69
|
+
* The API key that will be used to authenticate with Anthropic's API.
|
|
70
|
+
*
|
|
71
|
+
* The key is wrapped in a `Redacted` type to prevent accidental logging or
|
|
72
|
+
* exposure in debugging output, helping maintain security best practices.
|
|
73
|
+
*
|
|
74
|
+
* The key is automatically included in the `x-api-key` header for all API
|
|
75
|
+
* requests made through this client, which is automatically redacted in logs
|
|
76
|
+
* output by Effect loggers.
|
|
77
|
+
*
|
|
78
|
+
* Leave `undefined` if authentication will be handled through other means
|
|
79
|
+
* (e.g., environment-based authentication, proxy authentication, or when
|
|
80
|
+
* using a mock server that doesn't require authentication).
|
|
81
|
+
*/
|
|
39
82
|
readonly apiKey?: Redacted.Redacted | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* The base URL endpoint used to communicate with Anthropic's API.
|
|
85
|
+
*
|
|
86
|
+
* This property determines the HTTP destination for all API requests made by
|
|
87
|
+
* this client.
|
|
88
|
+
*
|
|
89
|
+
* Defaults to `"https://api.anthropic.com"`.
|
|
90
|
+
*
|
|
91
|
+
* Override this value when you need to:
|
|
92
|
+
* - Point to a different Anthropic environment (e.g., staging or sandbox
|
|
93
|
+
* servers).
|
|
94
|
+
* - Use a proxy between your application and Anthropic's API for security,
|
|
95
|
+
* caching, or logging.
|
|
96
|
+
* - Employ a mock server for local development or testing.
|
|
97
|
+
*
|
|
98
|
+
* You may leave this property `undefined` to accept the default value.
|
|
99
|
+
*/
|
|
40
100
|
readonly apiUrl?: string | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* The Anthropic API version to use for requests.
|
|
103
|
+
*
|
|
104
|
+
* This version string determines which API schema and features are available
|
|
105
|
+
* for your requests. Different versions may have different capabilities,
|
|
106
|
+
* request/response formats, or available models.
|
|
107
|
+
*
|
|
108
|
+
* Defaults to `"2023-06-01"`.
|
|
109
|
+
*
|
|
110
|
+
* You should specify a version that:
|
|
111
|
+
* - Supports the features and models you need
|
|
112
|
+
* - Is stable and well-tested for your use case
|
|
113
|
+
* - Matches your application's integration requirements
|
|
114
|
+
*
|
|
115
|
+
* Consult Anthropic's API documentation for available versions and their
|
|
116
|
+
* differences.
|
|
117
|
+
*/
|
|
41
118
|
readonly anthropicVersion?: string | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* The organization ID to associate with API requests.
|
|
121
|
+
*
|
|
122
|
+
* This identifier links requests to a specific organization within your
|
|
123
|
+
* Anthropic account, enabling proper billing, usage tracking, and access
|
|
124
|
+
* control at the organizational level.
|
|
125
|
+
*
|
|
126
|
+
* Provide this when:
|
|
127
|
+
* - Your account belongs to multiple organizations
|
|
128
|
+
* - You need to ensure requests are billed to the correct organization
|
|
129
|
+
* - Organization-level access policies apply to your use case
|
|
130
|
+
*
|
|
131
|
+
* Leave `undefined` if you're using a personal account or the default
|
|
132
|
+
* organization.
|
|
133
|
+
*/
|
|
42
134
|
readonly organizationId?: Redacted.Redacted | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* The project ID to associate with API requests.
|
|
137
|
+
*
|
|
138
|
+
* This identifier scopes requests to a specific project within your
|
|
139
|
+
* organization, enabling granular resource management, billing allocation,
|
|
140
|
+
* and access control at the project level.
|
|
141
|
+
*
|
|
142
|
+
* Specify this when:
|
|
143
|
+
* - You have multiple projects and need to separate their API usage
|
|
144
|
+
* - Project-level billing or quota management is required
|
|
145
|
+
* - Access policies are configured at the project level
|
|
146
|
+
*
|
|
147
|
+
* Leave `undefined` to use the default project or when project-level
|
|
148
|
+
* scoping is not needed.
|
|
149
|
+
*/
|
|
43
150
|
readonly projectId?: Redacted.Redacted | undefined;
|
|
151
|
+
/**
|
|
152
|
+
* A function to transform the underlying HTTP client before it's used for API requests.
|
|
153
|
+
*
|
|
154
|
+
* This transformation function receives the configured HTTP client and returns
|
|
155
|
+
* a modified version. It's applied after all standard client configuration
|
|
156
|
+
* (authentication, base URL, headers) but before any requests are made.
|
|
157
|
+
*
|
|
158
|
+
* Use this for:
|
|
159
|
+
* - Adding custom middleware (logging, metrics, caching)
|
|
160
|
+
* - Modifying request/response processing behavior
|
|
161
|
+
* - Adding custom retry logic or error handling
|
|
162
|
+
* - Integrating with monitoring or debugging tools
|
|
163
|
+
* - Applying organization-specific HTTP client policies
|
|
164
|
+
*
|
|
165
|
+
* The transformation is applied once during client initialization and affects
|
|
166
|
+
* all subsequent API requests made through this client instance.
|
|
167
|
+
*
|
|
168
|
+
* Leave `undefined` if no custom HTTP client behavior is needed.
|
|
169
|
+
*/
|
|
44
170
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
|
|
45
|
-
}) => Effect.Effect<
|
|
171
|
+
}) => Effect.Effect<Service, never, HttpClient.HttpClient | Scope.Scope>;
|
|
172
|
+
declare const PingEvent_base: Schema.Class<PingEvent, {
|
|
173
|
+
type: Schema.Literal<["ping"]>;
|
|
174
|
+
}, Schema.Struct.Encoded<{
|
|
175
|
+
type: Schema.Literal<["ping"]>;
|
|
176
|
+
}>, never, {
|
|
177
|
+
readonly type: "ping";
|
|
178
|
+
}, {}, {}>;
|
|
179
|
+
/**
|
|
180
|
+
* @since 1.0.0
|
|
181
|
+
* @category Schemas
|
|
182
|
+
*/
|
|
183
|
+
export declare class PingEvent extends PingEvent_base {
|
|
184
|
+
}
|
|
185
|
+
declare const ErrorEvent_base: Schema.Class<ErrorEvent, {
|
|
186
|
+
type: Schema.Literal<["error"]>;
|
|
187
|
+
error: Schema.Struct<{
|
|
188
|
+
type: Schema.Literal<["invalid_request_error", "authentication_error", "permission_error", "not_found_error", "request_too_large", "rate_limit_error", "api_error", "overloaded_error"]>;
|
|
189
|
+
message: typeof Schema.String;
|
|
190
|
+
}>;
|
|
191
|
+
}, Schema.Struct.Encoded<{
|
|
192
|
+
type: Schema.Literal<["error"]>;
|
|
193
|
+
error: Schema.Struct<{
|
|
194
|
+
type: Schema.Literal<["invalid_request_error", "authentication_error", "permission_error", "not_found_error", "request_too_large", "rate_limit_error", "api_error", "overloaded_error"]>;
|
|
195
|
+
message: typeof Schema.String;
|
|
196
|
+
}>;
|
|
197
|
+
}>, never, {
|
|
198
|
+
readonly type: "error";
|
|
199
|
+
} & {
|
|
200
|
+
readonly error: {
|
|
201
|
+
readonly type: "invalid_request_error" | "authentication_error" | "permission_error" | "not_found_error" | "rate_limit_error" | "api_error" | "overloaded_error" | "request_too_large";
|
|
202
|
+
readonly message: string;
|
|
203
|
+
};
|
|
204
|
+
}, {}, {}>;
|
|
205
|
+
/**
|
|
206
|
+
* @since 1.0.0
|
|
207
|
+
* @category Schemas
|
|
208
|
+
*/
|
|
209
|
+
export declare class ErrorEvent extends ErrorEvent_base {
|
|
210
|
+
}
|
|
211
|
+
declare const MessageStartEvent_base: Schema.Class<MessageStartEvent, {
|
|
212
|
+
type: Schema.Literal<["message_start"]>;
|
|
213
|
+
message: typeof Generated.BetaMessage;
|
|
214
|
+
}, Schema.Struct.Encoded<{
|
|
215
|
+
type: Schema.Literal<["message_start"]>;
|
|
216
|
+
message: typeof Generated.BetaMessage;
|
|
217
|
+
}>, never, {
|
|
218
|
+
readonly type: "message_start";
|
|
219
|
+
} & {
|
|
220
|
+
readonly message: Generated.BetaMessage;
|
|
221
|
+
}, {}, {}>;
|
|
222
|
+
/**
|
|
223
|
+
* @since 1.0.0
|
|
224
|
+
* @category Schemas
|
|
225
|
+
*/
|
|
226
|
+
export declare class MessageStartEvent extends MessageStartEvent_base {
|
|
227
|
+
}
|
|
228
|
+
declare const ServerToolUsage_base: Schema.Class<ServerToolUsage, {
|
|
229
|
+
/**
|
|
230
|
+
* The number of web search tool requests.
|
|
231
|
+
*/
|
|
232
|
+
web_search_requests: Schema.optionalWith<Schema.NullOr<Schema.filter<typeof Schema.Int>>, {
|
|
233
|
+
default: () => number;
|
|
234
|
+
}>;
|
|
235
|
+
}, Schema.Struct.Encoded<{
|
|
236
|
+
/**
|
|
237
|
+
* The number of web search tool requests.
|
|
238
|
+
*/
|
|
239
|
+
web_search_requests: Schema.optionalWith<Schema.NullOr<Schema.filter<typeof Schema.Int>>, {
|
|
240
|
+
default: () => number;
|
|
241
|
+
}>;
|
|
242
|
+
}>, never, {
|
|
243
|
+
readonly web_search_requests?: number | null | undefined;
|
|
244
|
+
}, {}, {}>;
|
|
245
|
+
/**
|
|
246
|
+
* @since 1.0.0
|
|
247
|
+
* @category Schemas
|
|
248
|
+
*/
|
|
249
|
+
export declare class ServerToolUsage extends ServerToolUsage_base {
|
|
250
|
+
}
|
|
251
|
+
declare const MessageDelta_base: Schema.Class<MessageDelta, {
|
|
252
|
+
stop_reason: Schema.optionalWith<Schema.NullOr<Schema.Literal<["end_turn", "max_tokens", "stop_sequence", "tool_use", "pause_turn", "refusal"]>>, {
|
|
253
|
+
default: () => null;
|
|
254
|
+
}>;
|
|
255
|
+
stop_sequence: Schema.optionalWith<Schema.NullOr<typeof Schema.String>, {
|
|
256
|
+
default: () => null;
|
|
257
|
+
}>;
|
|
258
|
+
}, Schema.Struct.Encoded<{
|
|
259
|
+
stop_reason: Schema.optionalWith<Schema.NullOr<Schema.Literal<["end_turn", "max_tokens", "stop_sequence", "tool_use", "pause_turn", "refusal"]>>, {
|
|
260
|
+
default: () => null;
|
|
261
|
+
}>;
|
|
262
|
+
stop_sequence: Schema.optionalWith<Schema.NullOr<typeof Schema.String>, {
|
|
263
|
+
default: () => null;
|
|
264
|
+
}>;
|
|
265
|
+
}>, never, {
|
|
266
|
+
readonly stop_sequence?: string | null | undefined;
|
|
267
|
+
} & {
|
|
268
|
+
readonly stop_reason?: "tool_use" | "max_tokens" | "end_turn" | "stop_sequence" | "pause_turn" | "refusal" | null | undefined;
|
|
269
|
+
}, {}, {}>;
|
|
270
|
+
/**
|
|
271
|
+
* @since 1.0.0
|
|
272
|
+
* @category Schemas
|
|
273
|
+
*/
|
|
274
|
+
export declare class MessageDelta extends MessageDelta_base {
|
|
275
|
+
}
|
|
276
|
+
declare const MessageDeltaUsage_base: Schema.Class<MessageDeltaUsage, {
|
|
277
|
+
/**
|
|
278
|
+
* The cumulative number of input tokens which were used.
|
|
279
|
+
*/
|
|
280
|
+
input_tokens: Schema.optionalWith<Schema.NullOr<Schema.filter<typeof Schema.Int>>, {
|
|
281
|
+
default: () => null;
|
|
282
|
+
}>;
|
|
283
|
+
/**
|
|
284
|
+
* The cumulative number of output tokens which were used.
|
|
285
|
+
*/
|
|
286
|
+
output_tokens: Schema.optionalWith<Schema.NullOr<Schema.filter<typeof Schema.Int>>, {
|
|
287
|
+
default: () => null;
|
|
288
|
+
}>;
|
|
289
|
+
/**
|
|
290
|
+
* The cumulative number of input tokens used to create the cache entry.
|
|
291
|
+
*/
|
|
292
|
+
cache_creation_input_tokens: Schema.optionalWith<Schema.NullOr<Schema.filter<typeof Schema.Int>>, {
|
|
293
|
+
default: () => null;
|
|
294
|
+
}>;
|
|
295
|
+
/**
|
|
296
|
+
* The cumulative number of input tokens read from the cache.
|
|
297
|
+
*/
|
|
298
|
+
cache_read_input_tokens: Schema.optionalWith<Schema.NullOr<Schema.filter<typeof Schema.Int>>, {
|
|
299
|
+
default: () => null;
|
|
300
|
+
}>;
|
|
301
|
+
/**
|
|
302
|
+
* The number of server tool requests.
|
|
303
|
+
*/
|
|
304
|
+
server_tool_use: Schema.optionalWith<Schema.NullOr<typeof ServerToolUsage>, {
|
|
305
|
+
default: () => null;
|
|
306
|
+
}>;
|
|
307
|
+
}, Schema.Struct.Encoded<{
|
|
308
|
+
/**
|
|
309
|
+
* The cumulative number of input tokens which were used.
|
|
310
|
+
*/
|
|
311
|
+
input_tokens: Schema.optionalWith<Schema.NullOr<Schema.filter<typeof Schema.Int>>, {
|
|
312
|
+
default: () => null;
|
|
313
|
+
}>;
|
|
314
|
+
/**
|
|
315
|
+
* The cumulative number of output tokens which were used.
|
|
316
|
+
*/
|
|
317
|
+
output_tokens: Schema.optionalWith<Schema.NullOr<Schema.filter<typeof Schema.Int>>, {
|
|
318
|
+
default: () => null;
|
|
319
|
+
}>;
|
|
320
|
+
/**
|
|
321
|
+
* The cumulative number of input tokens used to create the cache entry.
|
|
322
|
+
*/
|
|
323
|
+
cache_creation_input_tokens: Schema.optionalWith<Schema.NullOr<Schema.filter<typeof Schema.Int>>, {
|
|
324
|
+
default: () => null;
|
|
325
|
+
}>;
|
|
326
|
+
/**
|
|
327
|
+
* The cumulative number of input tokens read from the cache.
|
|
328
|
+
*/
|
|
329
|
+
cache_read_input_tokens: Schema.optionalWith<Schema.NullOr<Schema.filter<typeof Schema.Int>>, {
|
|
330
|
+
default: () => null;
|
|
331
|
+
}>;
|
|
332
|
+
/**
|
|
333
|
+
* The number of server tool requests.
|
|
334
|
+
*/
|
|
335
|
+
server_tool_use: Schema.optionalWith<Schema.NullOr<typeof ServerToolUsage>, {
|
|
336
|
+
default: () => null;
|
|
337
|
+
}>;
|
|
338
|
+
}>, never, {
|
|
339
|
+
readonly server_tool_use?: ServerToolUsage | null | undefined;
|
|
340
|
+
} & {
|
|
341
|
+
readonly cache_creation_input_tokens?: number | null | undefined;
|
|
342
|
+
} & {
|
|
343
|
+
readonly cache_read_input_tokens?: number | null | undefined;
|
|
344
|
+
} & {
|
|
345
|
+
readonly input_tokens?: number | null | undefined;
|
|
346
|
+
} & {
|
|
347
|
+
readonly output_tokens?: number | null | undefined;
|
|
348
|
+
}, {}, {}>;
|
|
349
|
+
/**
|
|
350
|
+
* @since 1.0.0
|
|
351
|
+
* @category Schemas
|
|
352
|
+
*/
|
|
353
|
+
export declare class MessageDeltaUsage extends MessageDeltaUsage_base {
|
|
354
|
+
}
|
|
355
|
+
declare const MessageDeltaEvent_base: Schema.Class<MessageDeltaEvent, {
|
|
356
|
+
type: Schema.Literal<["message_delta"]>;
|
|
357
|
+
delta: typeof MessageDelta;
|
|
358
|
+
/**
|
|
359
|
+
* Billing and rate-limit usage.
|
|
360
|
+
*
|
|
361
|
+
* Anthropic's API bills and rate-limits by token counts, as tokens represent
|
|
362
|
+
* the underlying cost to our systems.
|
|
363
|
+
*
|
|
364
|
+
* Under the hood, the API transforms requests into a format suitable for the
|
|
365
|
+
* model. The model's output then goes through a parsing stage before becoming
|
|
366
|
+
* an API response. As a result, the token counts in `usage` will not match
|
|
367
|
+
* one-to-one with the exact visible content of an API request or response.
|
|
368
|
+
*
|
|
369
|
+
* For example, `output_tokens` will be non-zero, even for an empty string
|
|
370
|
+
* response from Claude.\n\nTotal input tokens in a request is the summation
|
|
371
|
+
* of `input_tokens`, `cache_creation_input_tokens`, and `cache_read_input_tokens`.
|
|
372
|
+
*/
|
|
373
|
+
usage: typeof MessageDeltaUsage;
|
|
374
|
+
}, Schema.Struct.Encoded<{
|
|
375
|
+
type: Schema.Literal<["message_delta"]>;
|
|
376
|
+
delta: typeof MessageDelta;
|
|
377
|
+
/**
|
|
378
|
+
* Billing and rate-limit usage.
|
|
379
|
+
*
|
|
380
|
+
* Anthropic's API bills and rate-limits by token counts, as tokens represent
|
|
381
|
+
* the underlying cost to our systems.
|
|
382
|
+
*
|
|
383
|
+
* Under the hood, the API transforms requests into a format suitable for the
|
|
384
|
+
* model. The model's output then goes through a parsing stage before becoming
|
|
385
|
+
* an API response. As a result, the token counts in `usage` will not match
|
|
386
|
+
* one-to-one with the exact visible content of an API request or response.
|
|
387
|
+
*
|
|
388
|
+
* For example, `output_tokens` will be non-zero, even for an empty string
|
|
389
|
+
* response from Claude.\n\nTotal input tokens in a request is the summation
|
|
390
|
+
* of `input_tokens`, `cache_creation_input_tokens`, and `cache_read_input_tokens`.
|
|
391
|
+
*/
|
|
392
|
+
usage: typeof MessageDeltaUsage;
|
|
393
|
+
}>, never, {
|
|
394
|
+
readonly type: "message_delta";
|
|
395
|
+
} & {
|
|
396
|
+
readonly usage: MessageDeltaUsage;
|
|
397
|
+
} & {
|
|
398
|
+
readonly delta: MessageDelta;
|
|
399
|
+
}, {}, {}>;
|
|
400
|
+
/**
|
|
401
|
+
* @since 1.0.0
|
|
402
|
+
* @category Schemas
|
|
403
|
+
*/
|
|
404
|
+
export declare class MessageDeltaEvent extends MessageDeltaEvent_base {
|
|
405
|
+
}
|
|
406
|
+
declare const MessageStopEvent_base: Schema.Class<MessageStopEvent, {
|
|
407
|
+
type: Schema.Literal<["message_stop"]>;
|
|
408
|
+
}, Schema.Struct.Encoded<{
|
|
409
|
+
type: Schema.Literal<["message_stop"]>;
|
|
410
|
+
}>, never, {
|
|
411
|
+
readonly type: "message_stop";
|
|
412
|
+
}, {}, {}>;
|
|
413
|
+
/**
|
|
414
|
+
* @since 1.0.0
|
|
415
|
+
* @category Schemas
|
|
416
|
+
*/
|
|
417
|
+
export declare class MessageStopEvent extends MessageStopEvent_base {
|
|
418
|
+
}
|
|
419
|
+
declare const ContentBlockStartEvent_base: Schema.Class<ContentBlockStartEvent, {
|
|
420
|
+
type: Schema.Literal<["content_block_start"]>;
|
|
421
|
+
index: typeof Schema.Int;
|
|
422
|
+
content_block: typeof Generated.BetaContentBlock;
|
|
423
|
+
}, Schema.Struct.Encoded<{
|
|
424
|
+
type: Schema.Literal<["content_block_start"]>;
|
|
425
|
+
index: typeof Schema.Int;
|
|
426
|
+
content_block: typeof Generated.BetaContentBlock;
|
|
427
|
+
}>, never, {
|
|
428
|
+
readonly type: "content_block_start";
|
|
429
|
+
} & {
|
|
430
|
+
readonly index: number;
|
|
431
|
+
} & {
|
|
432
|
+
readonly content_block: Generated.BetaResponseTextBlock | Generated.BetaResponseThinkingBlock | Generated.BetaResponseRedactedThinkingBlock | Generated.BetaResponseToolUseBlock | Generated.BetaResponseServerToolUseBlock | Generated.BetaResponseWebSearchToolResultBlock | Generated.BetaResponseCodeExecutionToolResultBlock | Generated.BetaResponseBashCodeExecutionToolResultBlock | Generated.BetaResponseTextEditorCodeExecutionToolResultBlock | Generated.BetaResponseMCPToolUseBlock | Generated.BetaResponseMCPToolResultBlock | Generated.BetaResponseContainerUploadBlock;
|
|
433
|
+
}, {}, {}>;
|
|
434
|
+
/**
|
|
435
|
+
* @since 1.0.0
|
|
436
|
+
* @category Schemas
|
|
437
|
+
*/
|
|
438
|
+
export declare class ContentBlockStartEvent extends ContentBlockStartEvent_base {
|
|
439
|
+
}
|
|
440
|
+
declare const CitationsDelta_base: Schema.Class<CitationsDelta, {
|
|
441
|
+
type: Schema.Literal<["citations_delta"]>;
|
|
442
|
+
citation: Schema.Union<[typeof Generated.BetaResponseCharLocationCitation, typeof Generated.BetaResponsePageLocationCitation, typeof Generated.BetaResponseContentBlockLocationCitation, typeof Generated.BetaResponseWebSearchResultLocationCitation, typeof Generated.BetaResponseSearchResultLocationCitation]>;
|
|
443
|
+
}, Schema.Struct.Encoded<{
|
|
444
|
+
type: Schema.Literal<["citations_delta"]>;
|
|
445
|
+
citation: Schema.Union<[typeof Generated.BetaResponseCharLocationCitation, typeof Generated.BetaResponsePageLocationCitation, typeof Generated.BetaResponseContentBlockLocationCitation, typeof Generated.BetaResponseWebSearchResultLocationCitation, typeof Generated.BetaResponseSearchResultLocationCitation]>;
|
|
446
|
+
}>, never, {
|
|
447
|
+
readonly type: "citations_delta";
|
|
448
|
+
} & {
|
|
449
|
+
readonly citation: Generated.BetaResponseCharLocationCitation | Generated.BetaResponsePageLocationCitation | Generated.BetaResponseContentBlockLocationCitation | Generated.BetaResponseWebSearchResultLocationCitation | Generated.BetaResponseSearchResultLocationCitation;
|
|
450
|
+
}, {}, {}>;
|
|
451
|
+
/**
|
|
452
|
+
* @since 1.0.0
|
|
453
|
+
* @category Schemas
|
|
454
|
+
*/
|
|
455
|
+
export declare class CitationsDelta extends CitationsDelta_base {
|
|
456
|
+
}
|
|
457
|
+
declare const InputJsonContentBlockDelta_base: Schema.Class<InputJsonContentBlockDelta, {
|
|
458
|
+
type: Schema.Literal<["input_json_delta"]>;
|
|
459
|
+
partial_json: typeof Schema.String;
|
|
460
|
+
}, Schema.Struct.Encoded<{
|
|
461
|
+
type: Schema.Literal<["input_json_delta"]>;
|
|
462
|
+
partial_json: typeof Schema.String;
|
|
463
|
+
}>, never, {
|
|
464
|
+
readonly type: "input_json_delta";
|
|
465
|
+
} & {
|
|
466
|
+
readonly partial_json: string;
|
|
467
|
+
}, {}, {}>;
|
|
468
|
+
/**
|
|
469
|
+
* @since 1.0.0
|
|
470
|
+
* @category Schemas
|
|
471
|
+
*/
|
|
472
|
+
export declare class InputJsonContentBlockDelta extends InputJsonContentBlockDelta_base {
|
|
473
|
+
}
|
|
474
|
+
declare const SignatureContentBlockDelta_base: Schema.Class<SignatureContentBlockDelta, {
|
|
475
|
+
type: Schema.Literal<["signature_delta"]>;
|
|
476
|
+
signature: typeof Schema.String;
|
|
477
|
+
}, Schema.Struct.Encoded<{
|
|
478
|
+
type: Schema.Literal<["signature_delta"]>;
|
|
479
|
+
signature: typeof Schema.String;
|
|
480
|
+
}>, never, {
|
|
481
|
+
readonly type: "signature_delta";
|
|
482
|
+
} & {
|
|
483
|
+
readonly signature: string;
|
|
484
|
+
}, {}, {}>;
|
|
485
|
+
/**
|
|
486
|
+
* @since 1.0.0
|
|
487
|
+
* @category Schemas
|
|
488
|
+
*/
|
|
489
|
+
export declare class SignatureContentBlockDelta extends SignatureContentBlockDelta_base {
|
|
490
|
+
}
|
|
491
|
+
declare const TextContentBlockDelta_base: Schema.Class<TextContentBlockDelta, {
|
|
492
|
+
type: Schema.Literal<["text_delta"]>;
|
|
493
|
+
text: typeof Schema.String;
|
|
494
|
+
}, Schema.Struct.Encoded<{
|
|
495
|
+
type: Schema.Literal<["text_delta"]>;
|
|
496
|
+
text: typeof Schema.String;
|
|
497
|
+
}>, never, {
|
|
498
|
+
readonly type: "text_delta";
|
|
499
|
+
} & {
|
|
500
|
+
readonly text: string;
|
|
501
|
+
}, {}, {}>;
|
|
502
|
+
/**
|
|
503
|
+
* @since 1.0.0
|
|
504
|
+
* @category Schemas
|
|
505
|
+
*/
|
|
506
|
+
export declare class TextContentBlockDelta extends TextContentBlockDelta_base {
|
|
507
|
+
}
|
|
508
|
+
declare const ThinkingContentBlockDelta_base: Schema.Class<ThinkingContentBlockDelta, {
|
|
509
|
+
type: Schema.Literal<["thinking_delta"]>;
|
|
510
|
+
thinking: typeof Schema.String;
|
|
511
|
+
}, Schema.Struct.Encoded<{
|
|
512
|
+
type: Schema.Literal<["thinking_delta"]>;
|
|
513
|
+
thinking: typeof Schema.String;
|
|
514
|
+
}>, never, {
|
|
515
|
+
readonly type: "thinking_delta";
|
|
516
|
+
} & {
|
|
517
|
+
readonly thinking: string;
|
|
518
|
+
}, {}, {}>;
|
|
519
|
+
/**
|
|
520
|
+
* @since 1.0.0
|
|
521
|
+
* @category Schemas
|
|
522
|
+
*/
|
|
523
|
+
export declare class ThinkingContentBlockDelta extends ThinkingContentBlockDelta_base {
|
|
524
|
+
}
|
|
525
|
+
declare const ContentBlockDeltaEvent_base: Schema.Class<ContentBlockDeltaEvent, {
|
|
526
|
+
type: Schema.Literal<["content_block_delta"]>;
|
|
527
|
+
index: typeof Schema.Int;
|
|
528
|
+
delta: Schema.Union<[typeof CitationsDelta, typeof InputJsonContentBlockDelta, typeof SignatureContentBlockDelta, typeof TextContentBlockDelta, typeof ThinkingContentBlockDelta]>;
|
|
529
|
+
}, Schema.Struct.Encoded<{
|
|
530
|
+
type: Schema.Literal<["content_block_delta"]>;
|
|
531
|
+
index: typeof Schema.Int;
|
|
532
|
+
delta: Schema.Union<[typeof CitationsDelta, typeof InputJsonContentBlockDelta, typeof SignatureContentBlockDelta, typeof TextContentBlockDelta, typeof ThinkingContentBlockDelta]>;
|
|
533
|
+
}>, never, {
|
|
534
|
+
readonly type: "content_block_delta";
|
|
535
|
+
} & {
|
|
536
|
+
readonly delta: CitationsDelta | InputJsonContentBlockDelta | SignatureContentBlockDelta | TextContentBlockDelta | ThinkingContentBlockDelta;
|
|
537
|
+
} & {
|
|
538
|
+
readonly index: number;
|
|
539
|
+
}, {}, {}>;
|
|
540
|
+
/**
|
|
541
|
+
* @since 1.0.0
|
|
542
|
+
* @category Schemas
|
|
543
|
+
*/
|
|
544
|
+
export declare class ContentBlockDeltaEvent extends ContentBlockDeltaEvent_base {
|
|
545
|
+
}
|
|
546
|
+
declare const ContentBlockStopEvent_base: Schema.Class<ContentBlockStopEvent, {
|
|
547
|
+
type: Schema.Literal<["content_block_stop"]>;
|
|
548
|
+
index: typeof Schema.Int;
|
|
549
|
+
}, Schema.Struct.Encoded<{
|
|
550
|
+
type: Schema.Literal<["content_block_stop"]>;
|
|
551
|
+
index: typeof Schema.Int;
|
|
552
|
+
}>, never, {
|
|
553
|
+
readonly type: "content_block_stop";
|
|
554
|
+
} & {
|
|
555
|
+
readonly index: number;
|
|
556
|
+
}, {}, {}>;
|
|
557
|
+
/**
|
|
558
|
+
* @since 1.0.0
|
|
559
|
+
* @category Schemas
|
|
560
|
+
*/
|
|
561
|
+
export declare class ContentBlockStopEvent extends ContentBlockStopEvent_base {
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* @since 1.0.0
|
|
565
|
+
* @category Schemas
|
|
566
|
+
*/
|
|
567
|
+
export declare const MessageStreamEvent: Schema.Union<[typeof PingEvent, typeof ErrorEvent, typeof MessageStartEvent, typeof MessageDeltaEvent, typeof MessageStopEvent, typeof ContentBlockStartEvent, typeof ContentBlockDeltaEvent, typeof ContentBlockStopEvent]>;
|
|
568
|
+
/**
|
|
569
|
+
* @since 1.0.0
|
|
570
|
+
* @category Models
|
|
571
|
+
*/
|
|
572
|
+
export type MessageStreamEvent = typeof MessageStreamEvent.Type;
|
|
46
573
|
/**
|
|
47
574
|
* @since 1.0.0
|
|
48
575
|
* @category Layers
|
|
49
576
|
*/
|
|
50
577
|
export declare const layer: (options: {
|
|
578
|
+
/**
|
|
579
|
+
* The API key that will be used to authenticate with Anthropic's API.
|
|
580
|
+
*
|
|
581
|
+
* The key is wrapped in a `Redacted` type to prevent accidental logging or
|
|
582
|
+
* exposure in debugging output, helping maintain security best practices.
|
|
583
|
+
*
|
|
584
|
+
* The key is automatically included in the `x-api-key` header for all API
|
|
585
|
+
* requests made through this client, which is automatically redacted in logs
|
|
586
|
+
* output by Effect loggers.
|
|
587
|
+
*
|
|
588
|
+
* Leave `undefined` if authentication will be handled through other means
|
|
589
|
+
* (e.g., environment-based authentication, proxy authentication, or when
|
|
590
|
+
* using a mock server that doesn't require authentication).
|
|
591
|
+
*/
|
|
51
592
|
readonly apiKey?: Redacted.Redacted | undefined;
|
|
593
|
+
/**
|
|
594
|
+
* The base URL endpoint used to communicate with Anthropic's API.
|
|
595
|
+
*
|
|
596
|
+
* This property determines the HTTP destination for all API requests made by
|
|
597
|
+
* this client.
|
|
598
|
+
*
|
|
599
|
+
* Defaults to `"https://api.anthropic.com"`.
|
|
600
|
+
*
|
|
601
|
+
* Override this value when you need to:
|
|
602
|
+
* - Point to a different Anthropic environment (e.g., staging or sandbox
|
|
603
|
+
* servers).
|
|
604
|
+
* - Use a proxy between your application and Anthropic's API for security,
|
|
605
|
+
* caching, or logging.
|
|
606
|
+
* - Employ a mock server for local development or testing.
|
|
607
|
+
*
|
|
608
|
+
* You may leave this property `undefined` to accept the default value.
|
|
609
|
+
*/
|
|
52
610
|
readonly apiUrl?: string | undefined;
|
|
611
|
+
/**
|
|
612
|
+
* The Anthropic API version to use for requests.
|
|
613
|
+
*
|
|
614
|
+
* This version string determines which API schema and features are available
|
|
615
|
+
* for your requests. Different versions may have different capabilities,
|
|
616
|
+
* request/response formats, or available models.
|
|
617
|
+
*
|
|
618
|
+
* Defaults to `"2023-06-01"`.
|
|
619
|
+
*
|
|
620
|
+
* You should specify a version that:
|
|
621
|
+
* - Supports the features and models you need
|
|
622
|
+
* - Is stable and well-tested for your use case
|
|
623
|
+
* - Matches your application's integration requirements
|
|
624
|
+
*
|
|
625
|
+
* Consult Anthropic's API documentation for available versions and their
|
|
626
|
+
* differences.
|
|
627
|
+
*/
|
|
53
628
|
readonly anthropicVersion?: string | undefined;
|
|
629
|
+
/**
|
|
630
|
+
* A function to transform the underlying HTTP client before it's used for API requests.
|
|
631
|
+
*
|
|
632
|
+
* This transformation function receives the configured HTTP client and returns
|
|
633
|
+
* a modified version. It's applied after all standard client configuration
|
|
634
|
+
* (authentication, base URL, headers) but before any requests are made.
|
|
635
|
+
*
|
|
636
|
+
* Use this for:
|
|
637
|
+
* - Adding custom middleware (logging, metrics, caching)
|
|
638
|
+
* - Modifying request/response processing behavior
|
|
639
|
+
* - Adding custom retry logic or error handling
|
|
640
|
+
* - Integrating with monitoring or debugging tools
|
|
641
|
+
* - Applying organization-specific HTTP client policies
|
|
642
|
+
*
|
|
643
|
+
* The transformation is applied once during client initialization and affects
|
|
644
|
+
* all subsequent API requests made through this client instance.
|
|
645
|
+
*
|
|
646
|
+
* Leave `undefined` if no custom HTTP client behavior is needed.
|
|
647
|
+
*/
|
|
54
648
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
|
|
55
649
|
}) => Layer.Layer<AnthropicClient, never, HttpClient.HttpClient>;
|
|
56
650
|
/**
|
|
@@ -58,15 +652,77 @@ export declare const layer: (options: {
|
|
|
58
652
|
* @category Layers
|
|
59
653
|
*/
|
|
60
654
|
export declare const layerConfig: (options: {
|
|
655
|
+
/**
|
|
656
|
+
* The API key that will be used to authenticate with Anthropic's API.
|
|
657
|
+
*
|
|
658
|
+
* The key is wrapped in a `Redacted` type to prevent accidental logging or
|
|
659
|
+
* exposure in debugging output, helping maintain security best practices.
|
|
660
|
+
*
|
|
661
|
+
* The key is automatically included in the `x-api-key` header for all API
|
|
662
|
+
* requests made through this client, which is automatically redacted in logs
|
|
663
|
+
* output by Effect loggers.
|
|
664
|
+
*
|
|
665
|
+
* Leave `undefined` if authentication will be handled through other means
|
|
666
|
+
* (e.g., environment-based authentication, proxy authentication, or when
|
|
667
|
+
* using a mock server that doesn't require authentication).
|
|
668
|
+
*/
|
|
61
669
|
readonly apiKey?: Config.Config<Redacted.Redacted | undefined> | undefined;
|
|
670
|
+
/**
|
|
671
|
+
* The base URL endpoint used to communicate with Anthropic's API.
|
|
672
|
+
*
|
|
673
|
+
* This property determines the HTTP destination for all API requests made by
|
|
674
|
+
* this client.
|
|
675
|
+
*
|
|
676
|
+
* Defaults to `"https://api.anthropic.com"`.
|
|
677
|
+
*
|
|
678
|
+
* Override this value when you need to:
|
|
679
|
+
* - Point to a different Anthropic environment (e.g., staging or sandbox
|
|
680
|
+
* servers).
|
|
681
|
+
* - Use a proxy between your application and Anthropic's API for security,
|
|
682
|
+
* caching, or logging.
|
|
683
|
+
* - Employ a mock server for local development or testing.
|
|
684
|
+
*
|
|
685
|
+
* You may leave this property `undefined` to accept the default value.
|
|
686
|
+
*/
|
|
62
687
|
readonly apiUrl?: Config.Config<string | undefined> | undefined;
|
|
688
|
+
/**
|
|
689
|
+
* The Anthropic API version to use for requests.
|
|
690
|
+
*
|
|
691
|
+
* This version string determines which API schema and features are available
|
|
692
|
+
* for your requests. Different versions may have different capabilities,
|
|
693
|
+
* request/response formats, or available models.
|
|
694
|
+
*
|
|
695
|
+
* Defaults to `"2023-06-01"`.
|
|
696
|
+
*
|
|
697
|
+
* You should specify a version that:
|
|
698
|
+
* - Supports the features and models you need
|
|
699
|
+
* - Is stable and well-tested for your use case
|
|
700
|
+
* - Matches your application's integration requirements
|
|
701
|
+
*
|
|
702
|
+
* Consult Anthropic's API documentation for available versions and their
|
|
703
|
+
* differences.
|
|
704
|
+
*/
|
|
63
705
|
readonly anthropicVersion?: Config.Config<string | undefined> | undefined;
|
|
706
|
+
/**
|
|
707
|
+
* A function to transform the underlying HTTP client before it's used for API requests.
|
|
708
|
+
*
|
|
709
|
+
* This transformation function receives the configured HTTP client and returns
|
|
710
|
+
* a modified version. It's applied after all standard client configuration
|
|
711
|
+
* (authentication, base URL, headers) but before any requests are made.
|
|
712
|
+
*
|
|
713
|
+
* Use this for:
|
|
714
|
+
* - Adding custom middleware (logging, metrics, caching)
|
|
715
|
+
* - Modifying request/response processing behavior
|
|
716
|
+
* - Adding custom retry logic or error handling
|
|
717
|
+
* - Integrating with monitoring or debugging tools
|
|
718
|
+
* - Applying organization-specific HTTP client policies
|
|
719
|
+
*
|
|
720
|
+
* The transformation is applied once during client initialization and affects
|
|
721
|
+
* all subsequent API requests made through this client instance.
|
|
722
|
+
*
|
|
723
|
+
* Leave `undefined` if no custom HTTP client behavior is needed.
|
|
724
|
+
*/
|
|
64
725
|
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
|
|
65
726
|
}) => Layer.Layer<AnthropicClient, ConfigError, HttpClient.HttpClient>;
|
|
66
|
-
/**
|
|
67
|
-
* @since 1.0.0
|
|
68
|
-
* @category Models
|
|
69
|
-
*/
|
|
70
|
-
export type StreamCompletionRequest = Omit<typeof Generated.CreateMessageParams.Encoded, "stream">;
|
|
71
727
|
export {};
|
|
72
728
|
//# sourceMappingURL=AnthropicClient.d.ts.map
|