The best way to control Claude Code, Codex and more from any computer or phone
| 1 | /** |
| 2 | * The `OpenAiError` module defines OpenAI-specific metadata that can be |
| 3 | * attached to the shared `AiError` error types used by the AI packages. It is |
| 4 | * primarily used by OpenAI-compatible clients to preserve provider details |
| 5 | * such as error codes, error types, request IDs, and rate limit headers while |
| 6 | * still exposing errors through the provider-neutral Effect AI error model. |
| 7 | * |
| 8 | * Use this module when mapping OpenAI API failures into `AiError` values and |
| 9 | * when consumers need enough structured metadata to debug failed requests, |
| 10 | * inspect quota or rate limit responses, or correlate an error with OpenAI |
| 11 | * support. The exported types are metadata shapes only; the module augmentation |
| 12 | * makes those shapes available on the corresponding shared AI error metadata |
| 13 | * interfaces without defining new runtime error classes. |
| 14 | * |
| 15 | * @stability unstable |
| 16 | * @since 4.0.0 |
| 17 | */ |
| 18 | |
| 19 | /** |
| 20 | * OpenAI-specific error metadata fields. |
| 21 | * |
| 22 | * @stability unstable |
| 23 | * @category models |
| 24 | * @since 4.0.0 |
| 25 | */ |
| 26 | export type OpenAiErrorMetadata = { |
| 27 | /** |
| 28 | * The OpenAI error code returned by the API. |
| 29 | */ |
| 30 | readonly errorCode: string | null |
| 31 | /** |
| 32 | * The OpenAI error type returned by the API. |
| 33 | */ |
| 34 | readonly errorType: string | null |
| 35 | /** |
| 36 | * The unique request ID for debugging with OpenAI support. |
| 37 | */ |
| 38 | readonly requestId: string | null |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * OpenAI-specific rate limit metadata fields. |
| 43 | * |
| 44 | * **Details** |
| 45 | * |
| 46 | * Extends base error metadata with rate limit specific information from |
| 47 | * OpenAI's rate limit headers. |
| 48 | * |
| 49 | * @stability unstable |
| 50 | * @category models |
| 51 | * @since 4.0.0 |
| 52 | */ |
| 53 | export type OpenAiRateLimitMetadata = OpenAiErrorMetadata & { |
| 54 | /** |
| 55 | * The rate limit type (e.g. "requests", "tokens"). |
| 56 | */ |
| 57 | readonly limit: string | null |
| 58 | /** |
| 59 | * Number of remaining requests in the current window. |
| 60 | */ |
| 61 | readonly remaining: number | null |
| 62 | /** |
| 63 | * Time until the request rate limit resets. |
| 64 | */ |
| 65 | readonly resetRequests: string | null |
| 66 | /** |
| 67 | * Time until the token rate limit resets. |
| 68 | */ |
| 69 | readonly resetTokens: string | null |
| 70 | } |
| 71 | |
| 72 | declare module "effect/ai/AiError" { |
| 73 | /** |
| 74 | * Metadata attached to rate limit errors returned by OpenAI-compatible APIs. |
| 75 | * |
| 76 | * @category models |
| 77 | * @since 4.0.0 |
| 78 | */ |
| 79 | export interface RateLimitErrorMetadata { |
| 80 | readonly "openai-compat"?: OpenAiRateLimitMetadata | null |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Metadata attached when an OpenAI-compatible provider reports that quota or |
| 85 | * billing limits have been exhausted. |
| 86 | * |
| 87 | * @category models |
| 88 | * @since 4.0.0 |
| 89 | */ |
| 90 | export interface QuotaExhaustedErrorMetadata { |
| 91 | readonly "openai-compat"?: OpenAiErrorMetadata | null |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Metadata attached to authentication failures from OpenAI-compatible APIs, |
| 96 | * such as invalid, missing, or unauthorized API credentials. |
| 97 | * |
| 98 | * @category models |
| 99 | * @since 4.0.0 |
| 100 | */ |
| 101 | export interface AuthenticationErrorMetadata { |
| 102 | readonly "openai-compat"?: OpenAiErrorMetadata | null |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Metadata attached when an OpenAI-compatible provider rejects content because |
| 107 | * it violates a safety or usage policy. |
| 108 | * |
| 109 | * @category models |
| 110 | * @since 4.0.0 |
| 111 | */ |
| 112 | export interface ContentPolicyErrorMetadata { |
| 113 | readonly "openai-compat"?: OpenAiErrorMetadata | null |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Metadata attached to malformed or unsupported requests rejected by an |
| 118 | * OpenAI-compatible API before model execution. |
| 119 | * |
| 120 | * @category models |
| 121 | * @since 4.0.0 |
| 122 | */ |
| 123 | export interface InvalidRequestErrorMetadata { |
| 124 | readonly "openai-compat"?: OpenAiErrorMetadata | null |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Metadata attached to unexpected server-side failures reported by an |
| 129 | * OpenAI-compatible provider. |
| 130 | * |
| 131 | * @category models |
| 132 | * @since 4.0.0 |
| 133 | */ |
| 134 | export interface InternalProviderErrorMetadata { |
| 135 | readonly "openai-compat"?: OpenAiErrorMetadata | null |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Metadata attached when an OpenAI-compatible response cannot be converted |
| 140 | * into the expected AI package output shape. |
| 141 | * |
| 142 | * @category models |
| 143 | * @since 4.0.0 |
| 144 | */ |
| 145 | export interface InvalidOutputErrorMetadata { |
| 146 | readonly "openai-compat"?: OpenAiErrorMetadata | null |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Metadata attached when an OpenAI-compatible structured output response does |
| 151 | * not satisfy the requested schema or parsing constraints. |
| 152 | * |
| 153 | * @category models |
| 154 | * @since 4.0.0 |
| 155 | */ |
| 156 | export interface StructuredOutputErrorMetadata { |
| 157 | readonly "openai-compat"?: OpenAiErrorMetadata | null |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Metadata attached when an OpenAI-compatible provider cannot support the |
| 162 | * schema supplied for structured output or tool definitions. |
| 163 | * |
| 164 | * @category models |
| 165 | * @since 4.0.0 |
| 166 | */ |
| 167 | export interface UnsupportedSchemaErrorMetadata { |
| 168 | readonly "openai-compat"?: OpenAiErrorMetadata | null |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Metadata attached when an OpenAI-compatible error response cannot be mapped |
| 173 | * to a more specific shared AI error category. |
| 174 | * |
| 175 | * @category models |
| 176 | * @since 4.0.0 |
| 177 | */ |
| 178 | export interface UnknownErrorMetadata { |
| 179 | readonly "openai-compat"?: OpenAiErrorMetadata | null |
| 180 | } |
| 181 | } |