The best way to control Claude Code, Codex and more from any computer or phone
| 1 | /** |
| 2 | * OpenRouter error metadata augmentation. |
| 3 | * |
| 4 | * Provides OpenRouter-specific metadata fields for AI error types through |
| 5 | * module augmentation, enabling typed access to OpenRouter error details. |
| 6 | * |
| 7 | * @stability unstable |
| 8 | * @since 4.0.0 |
| 9 | */ |
| 10 | |
| 11 | /** |
| 12 | * OpenRouter-specific error metadata fields. |
| 13 | * |
| 14 | * @stability unstable |
| 15 | * @category models |
| 16 | * @since 4.0.0 |
| 17 | */ |
| 18 | export type OpenRouterErrorMetadata = { |
| 19 | /** |
| 20 | * The error code returned by the API. |
| 21 | */ |
| 22 | readonly errorCode: string | number | null |
| 23 | /** |
| 24 | * The error type returned by the API. |
| 25 | */ |
| 26 | readonly errorType: string | null |
| 27 | /** |
| 28 | * The unique request ID for debugging. |
| 29 | */ |
| 30 | readonly requestId: string | null |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * OpenRouter-specific rate limit metadata fields. |
| 35 | * |
| 36 | * @stability unstable |
| 37 | * @category models |
| 38 | * @since 4.0.0 |
| 39 | */ |
| 40 | export type OpenRouterRateLimitMetadata = OpenRouterErrorMetadata & { |
| 41 | readonly limit: string | null |
| 42 | readonly remaining: number | null |
| 43 | readonly resetRequests: string | null |
| 44 | readonly resetTokens: string | null |
| 45 | } |
| 46 | |
| 47 | declare module "effect/ai/AiError" { |
| 48 | /** |
| 49 | * OpenRouter metadata attached to `RateLimitError` values. |
| 50 | * |
| 51 | * **Details** |
| 52 | * |
| 53 | * Captures OpenRouter error details together with rate limit header |
| 54 | * information from responses where the provider rejected the request because |
| 55 | * a limit was reached. |
| 56 | * |
| 57 | * @category models |
| 58 | * @since 4.0.0 |
| 59 | */ |
| 60 | export interface RateLimitErrorMetadata { |
| 61 | /** |
| 62 | * OpenRouter-specific details for the rate limit response. |
| 63 | */ |
| 64 | readonly openrouter?: OpenRouterRateLimitMetadata | null |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * OpenRouter metadata attached to `QuotaExhaustedError` values. |
| 69 | * |
| 70 | * **Details** |
| 71 | * |
| 72 | * Preserves provider error details for failures caused by exhausted account, |
| 73 | * billing, or usage quota. |
| 74 | * |
| 75 | * @category models |
| 76 | * @since 4.0.0 |
| 77 | */ |
| 78 | export interface QuotaExhaustedErrorMetadata { |
| 79 | /** |
| 80 | * OpenRouter-specific details for the quota exhaustion response. |
| 81 | */ |
| 82 | readonly openrouter?: OpenRouterErrorMetadata | null |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * OpenRouter metadata attached to `AuthenticationError` values. |
| 87 | * |
| 88 | * **Details** |
| 89 | * |
| 90 | * Preserves provider error details for failed API key, authorization, or |
| 91 | * permission checks. |
| 92 | * |
| 93 | * @category models |
| 94 | * @since 4.0.0 |
| 95 | */ |
| 96 | export interface AuthenticationErrorMetadata { |
| 97 | /** |
| 98 | * OpenRouter-specific details for the authentication failure. |
| 99 | */ |
| 100 | readonly openrouter?: OpenRouterErrorMetadata | null |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * OpenRouter metadata attached to `ContentPolicyError` values. |
| 105 | * |
| 106 | * **Details** |
| 107 | * |
| 108 | * Preserves provider error details when OpenRouter rejects input or output |
| 109 | * because it violates a content policy. |
| 110 | * |
| 111 | * @category models |
| 112 | * @since 4.0.0 |
| 113 | */ |
| 114 | export interface ContentPolicyErrorMetadata { |
| 115 | /** |
| 116 | * OpenRouter-specific details for the content policy response. |
| 117 | */ |
| 118 | readonly openrouter?: OpenRouterErrorMetadata | null |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * OpenRouter metadata attached to `InvalidRequestError` values. |
| 123 | * |
| 124 | * **Details** |
| 125 | * |
| 126 | * Preserves provider error details for malformed requests, unsupported |
| 127 | * parameters, or other request validation failures reported by OpenRouter. |
| 128 | * |
| 129 | * @category models |
| 130 | * @since 4.0.0 |
| 131 | */ |
| 132 | export interface InvalidRequestErrorMetadata { |
| 133 | /** |
| 134 | * OpenRouter-specific details for the invalid request response. |
| 135 | */ |
| 136 | readonly openrouter?: OpenRouterErrorMetadata | null |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * OpenRouter metadata attached to `InternalProviderError` values. |
| 141 | * |
| 142 | * **Details** |
| 143 | * |
| 144 | * Preserves provider error details for OpenRouter-side failures such as |
| 145 | * transient server errors or overload responses. |
| 146 | * |
| 147 | * @category models |
| 148 | * @since 4.0.0 |
| 149 | */ |
| 150 | export interface InternalProviderErrorMetadata { |
| 151 | /** |
| 152 | * OpenRouter-specific details for the internal provider response. |
| 153 | */ |
| 154 | readonly openrouter?: OpenRouterErrorMetadata | null |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * OpenRouter metadata attached to `InvalidOutputError` values. |
| 159 | * |
| 160 | * **Details** |
| 161 | * |
| 162 | * Preserves provider error details when an OpenRouter response cannot be |
| 163 | * parsed or validated as the expected output. |
| 164 | * |
| 165 | * @category models |
| 166 | * @since 4.0.0 |
| 167 | */ |
| 168 | export interface InvalidOutputErrorMetadata { |
| 169 | /** |
| 170 | * OpenRouter-specific details for the invalid output response. |
| 171 | */ |
| 172 | readonly openrouter?: OpenRouterErrorMetadata | null |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * OpenRouter metadata attached to `StructuredOutputError` values. |
| 177 | * |
| 178 | * **Details** |
| 179 | * |
| 180 | * Preserves provider error details when OpenRouter returns content that does |
| 181 | * not satisfy the requested structured output schema. |
| 182 | * |
| 183 | * @category models |
| 184 | * @since 4.0.0 |
| 185 | */ |
| 186 | export interface StructuredOutputErrorMetadata { |
| 187 | /** |
| 188 | * OpenRouter-specific details for the structured output failure. |
| 189 | */ |
| 190 | readonly openrouter?: OpenRouterErrorMetadata | null |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * OpenRouter metadata attached to `UnsupportedSchemaError` values. |
| 195 | * |
| 196 | * **Details** |
| 197 | * |
| 198 | * Preserves provider error details when an unsupported schema failure is |
| 199 | * associated with an OpenRouter response. |
| 200 | * |
| 201 | * @category models |
| 202 | * @since 4.0.0 |
| 203 | */ |
| 204 | export interface UnsupportedSchemaErrorMetadata { |
| 205 | /** |
| 206 | * OpenRouter-specific details for the unsupported schema failure. |
| 207 | */ |
| 208 | readonly openrouter?: OpenRouterErrorMetadata | null |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * OpenRouter metadata attached to `UnknownError` values. |
| 213 | * |
| 214 | * **Details** |
| 215 | * |
| 216 | * Preserves provider error details for OpenRouter failures that do not map |
| 217 | * cleanly to a more specific AI error category. |
| 218 | * |
| 219 | * @category models |
| 220 | * @since 4.0.0 |
| 221 | */ |
| 222 | export interface UnknownErrorMetadata { |
| 223 | /** |
| 224 | * OpenRouter-specific details for the unclassified provider failure. |
| 225 | */ |
| 226 | readonly openrouter?: OpenRouterErrorMetadata | null |
| 227 | } |
| 228 | } |