Agent skill

Error Handling

by majiayu000 in majiayu000/litellm-rs

LiteLLM-RS Error Handling Architecture. An agent skill from majiayu000/litellm-rs.

MITAuto-check passedDevelopment

Install Error Handling

skills CLI
$ npx skills add majiayu000/litellm-rs --skill error-handling -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install majiayu000/litellm-rs error-handling --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/majiayu000/litellm-rs.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/error-handling .claude/skills/error-handling && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
error-handling
GitHub stars
117
Token cost
~2k tokens
SKILL.md length
205 words
Files
6
Skills in repo
9
Repo updated
First seen
Licence
MIT

At a glance

LiteLLM-RS Error Handling Architecture. An agent skill from majiayu000/litellm-rs.

  • Works in 5 steps: Always Use Factory Methods → Include Provider Name → Preserve Error Context → …
  • Designing error types
  • SKILL.md covers Two-Tier Error Hierarchy, HTTP Status Mapping, Best Practices and HTTP to ProviderError Mapping…, plus 1 more section
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Error Handling is an agent skill from majiayu000/litellm-rs. LiteLLM-RS Error Handling Architecture. Covers two-tier error hierarchy, ProviderError factory methods, HTTP status mapping, retry logic, and error context preservation. Use when designing error types or enums, creating ProviderError instances via factory methods, mapping HTTP statuses to typed errors, deciding retryability and backoff, or preserving error context.

Its SKILL.md is about 2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 6 other files (for example `reference/error-context-preservation.md`, `reference/factory-methods.md` and `reference/litellm-error-gateway.md`).

It sits in Development, covering Error handling and Model routing and gateways. It works with OpenAI and Rust. The repository describes itself as: Self-hosted Rust LLM gateway with OpenAI-compatible APIs, load balancing, failover, and a reusable Rust kernel. The licence is MIT.

When your agent uses it

  • Designing error types
  • Creating ProviderError instances via factory methods
  • Mapping HTTP statuses to typed errors
  • Deciding retryability and backoff

Example prompts

  • “/error-handling”

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. Always Use Factory Methods
  2. Include Provider Name
  3. Preserve Error Context
  4. Use Specific Error Types
  5. Handle All Error Variants in Match

What it can do on your machine

Read from SKILL.md and the folder at commit fb065f0. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are rust).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Error Handling loads about 2k tokens when it runs. Until then it costs about 96 tokens; SKILL.md has 205 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~96
When it runs · the whole SKILL.md, loaded when a task matches
~2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from majiayu000/litellm-rs at commit fb065f0, republished under its MIT licence (© majiayu000). 205 words, ~2,044 tokens.

Download SKILL.mdSave it as .claude/skills/error-handling/SKILL.md (or your agent's skills folder). This skill also uses 5 other files; get the full folder from GitHub.
name
error-handling
description
LiteLLM-RS Error Handling Architecture. Covers two-tier error hierarchy, ProviderError factory methods, HTTP status mapping, retry logic, and error context preservation. Use when designing error types or enums, creating ProviderError instances via factory methods, mapping HTTP statuses to typed errors, deciding retryability and backoff, or preserving error context.

Error Handling Architecture Guide

Two-Tier Error Hierarchy

LiteLLM-RS uses a two-tier error architecture spanning its provider catalog:

┌────────────────────────────────────────────────────────┐
│                    Gateway Layer                        │
│  LiteLLMError (core/types/errors/litellm.rs)          │
│  - Type alias for GatewayError                          │
│    (src/utils/error/gateway_error/types.rs)             │
│  - 18 variants for gateway-level errors                 │
└────────────────────────────────────────────────────────┘
                          ↓
┌────────────────────────────────────────────────────────┐
│                   Provider Layer                        │
│  ProviderError                                          │
│  (src/core/providers/unified_provider_error.rs;        │
│   exported as core::providers::ProviderError)           │
│  - 24 variants for provider-specific errors            │
│  - Each variant includes provider: &'static str        │
│  - Rich factory methods for error creation             │
└────────────────────────────────────────────────────────┘

HTTP Status Mapping

Standard Mapping Pattern

Most providers share one canonical status-to-error mapping, default_http_error_mapper in src/core/providers/unified_provider_http_mapping.rs:

rust
pub fn default_http_error_mapper(
    provider: &'static str,
    status_code: u16,
    response_body: &str,
) -> ProviderError {
    match status_code {
        400 => {
            let message = parse_error_message_from_body(response_body)
                .unwrap_or_else(|| response_body.to_string());
            ProviderError::invalid_request(provider, message)
        }
        401 => ProviderError::authentication(provider, "Invalid API key"),
        403 => ProviderError::authentication(provider, "Permission denied"),
        404 => ProviderError::model_not_found(provider, "Model not found"),
        429 => {
            let retry_after =
                crate::core::providers::shared::parse_retry_after_from_body(response_body);
            ProviderError::rate_limit(provider, retry_after)
        }
        500..=599 => ProviderError::api_error(provider, status_code, response_body),
        _ => ProviderError::api_error(provider, status_code, response_body),
    }
}

Providers needing extra special cases call extended_http_error_mapper (same file), which additionally maps 402 to quota_exceeded, 408/504 to timeout, 413 to context_length_exceeded, and 502/503 to provider_unavailable.

ErrorMapper Trait
rust
// src/core/traits/error_mapper/trait_def.rs

pub trait ErrorMapper<E>: Send + Sync + 'static
where
    E: ProviderErrorTrait,
{
    // Required: map HTTP status + body to the provider's error type
    fn map_http_error(&self, status_code: u16, response_body: &str) -> E;

    // Default implementations
    fn map_json_error(&self, error_response: &serde_json::Value) -> E;
    fn map_network_error(&self, error: &dyn std::error::Error) -> E;
    fn map_parsing_error(&self, error: &dyn std::error::Error) -> E;
    fn map_timeout_error(&self, timeout_duration: std::time::Duration) -> E;
}

GenericErrorMapper (src/core/traits/error_mapper/types.rs, re-exported as DefaultErrorMapper) implements ErrorMapper<E> for any E: ProviderErrorTrait:

rust
impl<E> ErrorMapper<E> for GenericErrorMapper
where
    E: ProviderErrorTrait,
{
    fn map_http_error(&self, status_code: u16, response_body: &str) -> E {
        match status_code {
            400 => E::network_error("Bad Request: Invalid parameters"),
            401 => E::authentication_failed("Authentication failed: Invalid credentials"),
            403 => E::authentication_failed("Permission denied: Insufficient permissions"),
            404 => E::not_supported("Resource not found"),
            408 => E::network_error("Request timeout"),
            429 => E::rate_limited(None),
            500 => E::network_error("Internal server error"),
            502 => E::network_error("Bad gateway: Upstream server error"),
            503 => E::network_error("Service unavailable: Server overloaded"),
            504 => E::network_error("Gateway timeout: Upstream timeout"),
            _ => E::network_error(/* "HTTP Error {status}: {body or default}" */),
        }
    }
}

Best Practices

1. Always Use Factory Methods
rust
// Good
ProviderError::authentication(PROVIDER_NAME, "Invalid API key")

// Bad - verbose and error-prone
ProviderError::Authentication {
    provider: PROVIDER_NAME,
    message: "Invalid API key".to_string(),
}
2. Include Provider Name
rust
// Good - error clearly identifies source
ProviderError::network("openai", "Connection refused")

// Bad - unclear which provider failed
ProviderError::network("unknown", "Connection refused")
3. Preserve Error Context
rust
// Good - execute_request already returns a classified ProviderError
let response = self.pool_manager
    .execute_request(&url, method, headers, body)
    .await?;

// Bad - erases an existing typed error by reclassifying it as Network
self.pool_manager.execute_request(&url, method, headers, body)
    .await
    .map_err(|e| ProviderError::network(PROVIDER_NAME, e.to_string()))?
4. Use Specific Error Types
rust
// Good - specific error type
if response.status() == 429 {
    return Err(ProviderError::rate_limit(PROVIDER_NAME, retry_after));
}

// Bad - generic error loses information
if !response.status().is_success() {
    return Err(ProviderError::api_error(PROVIDER_NAME, status, "Failed"));
}
5. Handle All Error Variants in Match
rust
// Good - exhaustive handling
match error {
    ProviderError::RateLimit { retry_after, .. } => {
        if let Some(delay) = retry_after {
            tokio::time::sleep(Duration::from_secs(delay)).await;
        }
        // Retry...
    }
    ProviderError::Authentication { .. } => {
        // Don't retry, return immediately
        return Err(error);
    }
    e if RetryPolicy
        .decide(&router_config, e, retry_context)
        .should_retry =>
    {
        // Retry per decision.delay (see reference/retry-logic.md).
        // Note: error.is_retryable() is deprecated since 0.6.0.
    }
    _ => return Err(error),
}

HTTP to ProviderError Mapping Reference

Canonical behavior of default_http_error_mapper:

HTTP StatusResultLegacy-retryable
400invalid_request (message parsed from body)No
401authentication ("Invalid API key")No
403authentication ("Permission denied")No
404model_not_foundNo
429rate_limit (retry-after parsed from body when present)Yes
500-599api_error(status)Yes
otherapi_error(status)No

extended_http_error_mapper adds: 402→quota_exceeded, 408/504→timeout, 413→context_length_exceeded, 502/503→provider_unavailable.

References

© majiayu000, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 5 other files in .claude/skills/error-handling of majiayu000/litellm-rs.

  • SKILL.md
  • reference/error-context-preservation.md
  • reference/factory-methods.md
  • reference/litellm-error-gateway.md
  • reference/provider-error-variants.md
  • reference/retry-logic.md

Open the folder on GitHubat commit fb065f0

Compare with similar skills

Error Handling next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Error Handling compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Error Handling this skillmajiayu000/litellm-rs117—~2kAutomated safety check: PassMIT
Evaluating Bitrouter Routesbitrouter/bitrouter235—~1.2kAutomated safety check: PassApache-2.0
Run Bitrouter Benchmarkbitrouter/bitrouter235—~2.2kAutomated safety check: PassApache-2.0
Run Shuntpleaseai/shunt281—~2.6kAutomated safety check: PassApache-2.0
Cross Evalalirezarezvani/claude-skills28k—~1.1kAutomated safety check: PassMIT
Rust Best Practicesfarm-fe/farm5.6k3 repos~1.1kAutomated safety check: PassMIT

Similar skills

  • Evaluating Bitrouter Routes

    bitrouter/bitrouter

    A skill your agent uses when evaluating BitRouter route decisions or Eval Exchange subjects with task-native verifiers, human reviewers, private enterprise evaluators, agentic judges, or genuinely…

    235 GitHub stars~1.2k tokensUpdated yesterday
    AI & LLM EngineeringAuto-check passed
  • Run Bitrouter Benchmark

    bitrouter/bitrouter

    A skill your agent uses when a user wants to run, compare, resume, audit, share, or submit a Harbor benchmark through BitRouter, including choosing a Harbor dataset and agent, confirming routed…

    235 GitHub stars~2.2k tokensUpdated yesterday
    AI & LLM EngineeringAuto-check passed
  • Run Shunt

    pleaseai/shunt

    Build, launch, and drive shunt — the Claude Code LLM gateway (a Rust/axum Anthropic-Messages proxy).

    281 GitHub stars~2.6k tokensUpdated yesterday
    Testing & QAAuto-check passed
  • Cross Eval

    alirezarezvani/claude-skills

    /cs:cross-eval <memo — Multi-model consensus on a board memo or strategy brief.

    28k GitHub stars~1.1k tokensUpdated 1 mo ago
    DevelopmentAuto-check passed
  • Guide for writing idiomatic Rust code based on Apollo GraphQL's best practices handbook.

    5.6k GitHub starsUsed in 3 repos~1.1k tokens
    DevelopmentAuto-check passed
  • Rust Async Patterns

    diodeme/Gold-Band

    Master Rust async programming with Tokio, async traits, error handling, and concurrent patterns.

    143 GitHub starsUsed in 10 repos~3.1k tokens
    DevelopmentAuto-check passed

More from majiayu000/litellm-rs

All 9 skills in this repo
  • Auth Architecture

    majiayu000/litellm-rs

    LiteLLM-RS Authentication Architecture. An agent skill from majiayu000/litellm-rs.

    117 GitHub stars~1.9k tokensUpdated yesterday
    Auto-check passed
  • Caching Architecture

    majiayu000/litellm-rs

    LiteLLM-RS response caching architecture. An agent skill from majiayu000/litellm-rs.

    117 GitHub stars~2k tokensUpdated yesterday
    Auto-check passed
  • Config Architecture

    majiayu000/litellm-rs

    LiteLLM-RS Configuration Architecture. An agent skill from majiayu000/litellm-rs.

    117 GitHub stars~3.2k tokensUpdated yesterday
    Auto-check passed
  • Observability Architecture

    majiayu000/litellm-rs

    LiteLLM-RS Observability Architecture. An agent skill from majiayu000/litellm-rs.

    117 GitHub stars~1.3k tokensUpdated yesterday
    Auto-check passed
  • Provider Architecture

    majiayu000/litellm-rs

    LiteLLM-RS provider system in two tiers - data-driven OpenAI-compatible catalog entries auto-routed through OpenAILikeProvider, plus code-based provider modules implementing the LLMProvider trait…

    117 GitHub stars~4.9k tokensUpdated yesterday
    Auto-check passed
  • Routing Architecture

    majiayu000/litellm-rs

    LiteLLM-RS Routing Architecture. An agent skill from majiayu000/litellm-rs.

    117 GitHub stars~1.9k tokensUpdated yesterday
    Auto-check passed

Works with

Questions about Error Handling

What does Error Handling do?

LiteLLM-RS Error Handling Architecture. An agent skill from majiayu000/litellm-rs. Error Handling is an agent skill from majiayu000/litellm-rs. LiteLLM-RS Error Handling Architecture.

When should I use Error Handling?

Error Handling fits situations like: designing error types; creating ProviderError instances via factory methods; mapping HTTP statuses to typed errors; deciding retryability and backoff.

How do I install Error Handling in Claude Code?

Run `npx skills add majiayu000/litellm-rs --skill error-handling -a claude-code`. Or copy the skill folder (.claude/skills/error-handling in majiayu000/litellm-rs) into .claude/skills/error-handling in your project. Claude Code loads it when a task matches its description.

How do I install Error Handling in Codex?

Run `npx skills add majiayu000/litellm-rs --skill error-handling -a codex`. Or copy the skill folder (.claude/skills/error-handling in majiayu000/litellm-rs) into .agents/skills/error-handling in your project. Codex loads it when a task matches its description.

Can I use Error Handling in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add majiayu000/litellm-rs --skill error-handling -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/error-handling, .gemini/skills/error-handling, .github/skills/error-handling and .opencode/skills/error-handling in your project.

What does Error Handling need to run?

SKILL.md names no scripts, command-line tools or credentials: Error Handling is instructions for the agent only.

Does Error Handling access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Error Handling safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Error Handling use?

Error Handling is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Error Handling use?

About 2k tokens (SKILL.md is roughly 8.2k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Error Handling?

Skills that share tags, products or a category with Error Handling: Evaluating Bitrouter Routes (bitrouter/bitrouter, 235 stars), Run Bitrouter Benchmark (bitrouter/bitrouter, 235 stars), Run Shunt (pleaseai/shunt, 281 stars) and Cross Eval (alirezarezvani/claude-skills, 28k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Error Handling?

majiayu000 (a GitHub user) maintains it in majiayu000/litellm-rs, which has 117 GitHub stars. The repository holds 9 skills in this directory. The repository was last updated on October 8, 2026.

Source: majiayu000/litellm-rs on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.