#pragma once // Perplexity error statuses and what to do about them. Sources: the OpenAPI // error responses, the FAQ ("Errors & Troubleshooting") and the Rate Limits // page. Waits are static advice; nothing here sleeps or retries on its own. // A 429 carries Retry-After, which llm::ApiError drops (src/llm gap): the // static floor below is used instead. #include #include "llm/error.h" namespace molo::perplexity { enum class ErrorKind { kNone, kBadRequest, kAuth, kPayment, kForbidden, kNotFound, kConflict, kTooLarge, kInvalidParams, kRateLimit, kServer, kBadGateway, kOverloaded, kGatewayTimeout, kTransport, kOther, }; struct ErrorInfo { int status; ErrorKind kind; const char* name; const char* cause; const char* action; bool retryable; // wait and retry the same request int min_wait_seconds; // floor before a retry; 0 when not retryable }; class Errors { public: static std::size_t count(); static const ErrorInfo& at(std::size_t index); static const ErrorInfo* find(int status); static ErrorKind kind_of(int status); static bool retryable(int status); // Static wait before a retry (0: do not retry). Hard cap kMaxWaitSeconds. static int wait_seconds(int status); static constexpr int kMaxWaitSeconds = 30; // The documented 429 error.type values. static bool is_rate_limit_type(const std::string& type); // One line for humans: "402 Payment Required: add credits ...". static std::string explain(const llm::ApiError& e); }; } // namespace molo::perplexity