You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ import { ResilientLLM } from 'resilient-llm';
34
34
35
35
constllm=newResilientLLM({
36
36
aiService:'openai', // or 'anthropic', 'google', 'ollama'
37
-
model:'gpt-4o-mini',
37
+
model:'gpt-5-nano',
38
38
maxTokens:2048,
39
39
temperature:0.7,
40
40
rateLimitConfig: {
@@ -61,6 +61,8 @@ const conversationHistory = [
61
61
})();
62
62
```
63
63
64
+
**Handling Error:** typescript users can import `ResilientLLMError` and use the `error.code` to deal with various errors. The canonical list is [`ResilientLLMErrorCode`](./lib/ResilientLLMError.ts) in the source. Javascript users can use the error object properties { name="ResilientLLMError", code, message, metadata, retryable }.
-**`ResilientLLMError`** — Normalized failures from `chat()` (after internal retries when applicable). Use **`error.code`** (`ResilientLLMErrorCode`), **`error.retryable`**, **`error.metadata`**, and **`error.cause`** (log server-side). The canonical code list is in [`lib/ResilientLLMError.ts`](../lib/ResilientLLMError.ts).
159
+
- Structured output failures use codes such as **`JSON_PARSE_ERROR`**, **`JSON_MODE_FAILURE`**, **`SCHEMA_MISMATCH`**, or **`VALIDATION_ERROR`**; details may appear on **`error.cause`**.
Parses errors from various LLM APIs to create uniform error messages. This method is called internally when errors occur.
292
+
Normalizes an error into **`ResilientLLMError`**. Used internally when `chat()` fails; you can call it directly if you need the same mapping (e.g. tests).
298
293
299
294
**Signature:**
300
295
```typescript
301
-
parseError(statusCode: number |null, error:Error|Object|null): never
296
+
parseError(statusCode: number |null, error:Error, operationMetadata?: OperationMetadata|null): never
302
297
```
303
298
304
299
**Parameters:**
305
300
306
301
| Parameter | Type | Required | Description |
307
302
|-----------|------|----------|-------------|
308
-
| `statusCode` | `number \|null` | Yes | HTTP status code or null for general errors |
**Throws:** `Error` with appropriate message based on status code
314
-
315
-
**Status Code Mappings:**
316
-
317
-
| Status Code | Error Message |
318
-
|------------|---------------|
319
-
| `400` | "Bad request" |
320
-
| `401` | "Invalid API Key" |
321
-
| `403` | "You are not authorized to access this resource" |
322
-
| `404` | "Not found" |
323
-
| `429` | "Rate limit exceeded" |
324
-
| `500` | "Internal server error" |
325
-
| `503` | "Service unavailable" |
326
-
| `529` | "API temporarily overloaded" |
327
-
| Other | "Unknown error" |
328
-
329
-
**Note:** This method is called internally by the `chat()` method when errors occur. You typically don't need to call it directly.
309
+
If `error` is already a **`ResilientLLMError`**, it is rethrown (metadata may be merged). Otherwise **`statusCode`** selects a **`PROVIDER_*`** code (e.g. `401` → `PROVIDER_UNAUTHORIZED`); `null` or unknown statuses map to **`PROVIDER_ERROR`**. See [`lib/ResilientLLMError.ts`](../lib/ResilientLLMError.ts) for the full `ResilientLLMErrorCode` union.
| `429` | Rate Limit Exceeded | Triggers retry with alternate service |
788
-
| `500` | Internal Server Error | Retries with backoff |
789
-
| `503` | Service Unavailable | Retries with backoff |
790
-
| `529` | API Overloaded | Triggers retry with alternate service |
758
+
Failures from **`chat()`** are thrown as **`ResilientLLMError`** (see `chat()` **Throws** above). That type is the consumer-facing surface: **`code`**, **`retryable`**, optional **`metadata`** (same shape as success), and **`cause`** for logging.
791
759
792
-
### Error Types
760
+
**Stable string codes** — **`ResilientLLMErrorCode`** in [`lib/ResilientLLMError.ts`](../lib/ResilientLLMError.ts) (including `PROVIDER_*`, structured-output codes, resilience-related codes, and configuration/capability codes). **`retryable`** is defined there for codes where a simple retry might help.
793
761
794
-
| Error Name | Description | Retry Behavior |
795
-
|------------|-------------|----------------|
796
-
| `AbortError` | Operation was aborted | No retry |
797
-
| `TimeoutError` | Operation timed out | Retries with backoff |
798
-
| `Error` (message: "Circuit breaker is open") | Circuit breaker is open | No retry until cooldown expires |
762
+
Use **`error.code`** for branching, not raw HTTP status. When a provider HTTP status was available to the library, it may also appear under **`metadata`** (e.g. `provider.httpStatus` / `http`).
799
763
800
764
---
801
765
@@ -917,7 +881,7 @@ Same format as OpenAI response.
917
881
Each service has a default model configured. Use `ProviderRegistry.getDefaultModels()` to get all default models:
918
882
919
883
- **Anthropic:** `claude-3-5-sonnet-20240620`
920
-
- **OpenAI:** `gpt-4o-mini`
884
+
- **OpenAI:** `gpt-5-nano`
921
885
- **Google:** `gemini-2.0-flash`
922
886
- **Ollama:** `llama3.1:8b`
923
887
@@ -1001,7 +965,7 @@ Timeouts are enforced using `AbortController`:
1001
965
1002
966
- Timeout applies to entire operation (including retries)
1003
967
- On timeout, `AbortController` aborts the HTTP request
1004
-
- Throws `TimeoutError` if operation exceeds timeout
968
+
- **`chat()`** rejects with **`ResilientLLMError`**; the original timeout is typically on **`error.cause`** (`name` may be `TimeoutError`)
0 commit comments