The best way to control Claude Code, Codex and more from any computer or phone

main
ts 215 lines 5.77 KB
Raw
1 /**
2 * Anthropic error metadata augmentation.
3 *
4 * Provides Anthropic-specific metadata fields for AI error types through module
5 * augmentation, enabling typed access to Anthropic error details.
6 *
7 * @stability unstable
8 * @since 4.0.0
9 */
10
11 /**
12 * Anthropic-specific error metadata fields.
13 *
14 * **Details**
15 *
16 * Contains the Anthropic error type and request identifier copied from provider
17 * error responses when available. Either field may be `null` when Anthropic
18 * does not include it or the response cannot be decoded.
19 *
20 * @see {@link AnthropicRateLimitMetadata} for rate-limit responses that also include parsed Anthropic rate-limit headers
21 *
22 * @stability unstable
23 * @category models
24 * @since 4.0.0
25 */
26 export type AnthropicErrorMetadata = {
27 /**
28 * The Anthropic error type returned by the API.
29 */
30 readonly errorType: string | null
31 /**
32 * The unique request ID for debugging with Anthropic support.
33 */
34 readonly requestId: string | null
35 }
36
37 /**
38 * Anthropic-specific rate limit metadata fields.
39 *
40 * **Details**
41 *
42 * Extends base error metadata with rate limit-specific information from Anthropic's rate limit headers.
43 *
44 * @stability unstable
45 * @category models
46 * @since 4.0.0
47 */
48 export type AnthropicRateLimitMetadata = AnthropicErrorMetadata & {
49 /**
50 * Number of requests allowed in the current period.
51 */
52 readonly requestsLimit: number | null
53 /**
54 * Number of requests remaining in the current period.
55 */
56 readonly requestsRemaining: number | null
57 /**
58 * Time when the request rate limit resets.
59 */
60 readonly requestsReset: string | null
61 /**
62 * Number of tokens allowed in the current period.
63 */
64 readonly tokensLimit: number | null
65 /**
66 * Number of tokens remaining in the current period.
67 */
68 readonly tokensRemaining: number | null
69 /**
70 * Time when the token rate limit resets.
71 */
72 readonly tokensReset: string | null
73 }
74
75 declare module "effect/ai/AiError" {
76 /**
77 * Anthropic metadata attached to `RateLimitError` values.
78 *
79 * **Details**
80 *
81 * Includes request identifiers, Anthropic error types, and parsed request or token limit headers when the provider rejects a request due to rate limits.
82 *
83 * @category models
84 * @since 4.0.0
85 */
86 export interface RateLimitErrorMetadata {
87 readonly anthropic?: AnthropicRateLimitMetadata | null
88 }
89
90 /**
91 * Anthropic metadata attached to `QuotaExhaustedError` values.
92 *
93 * **Details**
94 *
95 * Captures the Anthropic error type and request identifier for failures where the account or workspace has exhausted its available quota.
96 *
97 * @category models
98 * @since 4.0.0
99 */
100 export interface QuotaExhaustedErrorMetadata {
101 readonly anthropic?: AnthropicErrorMetadata | null
102 }
103
104 /**
105 * Anthropic metadata attached to `AuthenticationError` values.
106 *
107 * **Details**
108 *
109 * Preserves Anthropic error details for missing, invalid, or unauthorized API credentials while keeping the error in the shared AI error model.
110 *
111 * @category models
112 * @since 4.0.0
113 */
114 export interface AuthenticationErrorMetadata {
115 readonly anthropic?: AnthropicErrorMetadata | null
116 }
117
118 /**
119 * Anthropic metadata attached to `ContentPolicyError` values.
120 *
121 * **Details**
122 *
123 * Records Anthropic error details returned when a request or response is rejected by Anthropic safety or content policy enforcement.
124 *
125 * @category models
126 * @since 4.0.0
127 */
128 export interface ContentPolicyErrorMetadata {
129 readonly anthropic?: AnthropicErrorMetadata | null
130 }
131
132 /**
133 * Anthropic metadata attached to `InvalidRequestError` values.
134 *
135 * **Details**
136 *
137 * Provides the Anthropic error type and request identifier for malformed or unsupported requests rejected before model execution.
138 *
139 * @category models
140 * @since 4.0.0
141 */
142 export interface InvalidRequestErrorMetadata {
143 readonly anthropic?: AnthropicErrorMetadata | null
144 }
145
146 /**
147 * Anthropic metadata attached to `InternalProviderError` values.
148 *
149 * **Details**
150 *
151 * Preserves Anthropic request correlation data for provider-side failures that should be reported or investigated with Anthropic support.
152 *
153 * @category models
154 * @since 4.0.0
155 */
156 export interface InternalProviderErrorMetadata {
157 readonly anthropic?: AnthropicErrorMetadata | null
158 }
159
160 /**
161 * Anthropic metadata attached to `InvalidOutputError` values.
162 *
163 * **Details**
164 *
165 * Describes Anthropic-specific context for responses that could not be decoded or interpreted as valid AI output.
166 *
167 * @category models
168 * @since 4.0.0
169 */
170 export interface InvalidOutputErrorMetadata {
171 readonly anthropic?: AnthropicErrorMetadata | null
172 }
173
174 /**
175 * Anthropic metadata attached to `StructuredOutputError` values.
176 *
177 * **Details**
178 *
179 * Captures Anthropic error details for structured-output failures, including request correlation data useful when diagnosing schema-related responses.
180 *
181 * @category models
182 * @since 4.0.0
183 */
184 export interface StructuredOutputErrorMetadata {
185 readonly anthropic?: AnthropicErrorMetadata | null
186 }
187
188 /**
189 * Anthropic metadata attached to `UnsupportedSchemaError` values.
190 *
191 * **Details**
192 *
193 * Provides Anthropic error details for schemas that cannot be represented by or submitted to the Anthropic API.
194 *
195 * @category models
196 * @since 4.0.0
197 */
198 export interface UnsupportedSchemaErrorMetadata {
199 readonly anthropic?: AnthropicErrorMetadata | null
200 }
201
202 /**
203 * Anthropic metadata attached to `UnknownError` values.
204 *
205 * **Details**
206 *
207 * Retains the Anthropic error type and request identifier when a provider response cannot be classified as a more specific AI error.
208 *
209 * @category models
210 * @since 4.0.0
211 */
212 export interface UnknownErrorMetadata {
213 readonly anthropic?: AnthropicErrorMetadata | null
214 }
215 }