Skip to content
pi-c Documentation
Login

Documentation

/* The bundled reading of a provider's refusals and the words for a key's
 * state: which failures mean a dead key, no credit or a rate limit (vendor
 * wording kept as data rows, since it drifts), the sentences a user sees,
 * and which choices the swap prompt offers. Core records; this decides. The
 * composition root registers pic_keyhealth_ops with cred.h. */
#ifndef PIC_KEYHEALTH_H
#define PIC_KEYHEALTH_H

#include <stddef.h>

#include "cred.h"

extern const pic_cred_health_ops pic_keyhealth_ops;

/* A 429 is a limit (not retried) when it says to wait this long or longer. */
#define PIC_KEYHEALTH_LONG_MS 60000LL

void pic_keyhealth_classify(const char *provider, int status, const char *body, const char *message,
                            const char *ratelimit, const char *retry_after, long long now_ms, pic_key_health *h);
/* The error a request ends with: 'The key "main" for anthropic is out of credit (HTTP 402: ...).' */
void pic_keyhealth_message(const char *provider, const char *label, const pic_key_health *h, long long now_ms, char *out,
                           size_t cap);
/* The swap prompt's first line: 'The key "main" is out of credit. Nothing was lost.' */
void pic_keyhealth_headline(const char *provider, const char *label, const pic_key_health *h, long long now_ms, char *out,
                            size_t cap);
/* The choices the swap prompt offers for STATE, in order, as letters: s
 * (another key, only when HAVE_OTHER), m (another model), w (wait, for a
 * limit), l (log in again, for a refused key). Esc, to stop, always. */
const char *pic_keyhealth_offers(pic_key_state state, int have_other);
/* A key's state for a list: "ok, checked 2 min ago", "out of credit since 14:02 (HTTP 402)". */
void pic_keyhealth_phrase(const pic_key_health *h, long long now_ms, char *out, size_t cap);
/* The footer's warning for a bad state ("! out of credit", "! limited until 15:45",
 * "! refused"), or "" when there is none. */
void pic_keyhealth_alert(const pic_key_health *h, long long now_ms, char *out, size_t cap);
/* Whether H says not to use the key now (refused, no credit, or limited still). */
int pic_keyhealth_bad(const pic_key_health *h, long long now_ms);
/* "15:45 (38 min)". */
void pic_keyhealth_until(long long until_ms, long long now_ms, char *out, size_t cap);

#endif