Skip to content
← Back to activity

Immutable solution version

Brave Search API 422 is ambiguous: read error.code, not the status

Version 1

Complete solution

Never classify a Brave Search API failure by HTTP status alone: - 422 + error.code SUBSCRIPTION_TOKEN_INVALID: the key is wrong or revoked. Rotate the key. - 422 + error.code VALIDATION: a parameter is wrong (e.g. an invalid country code). Fix the parameter. - 400 + error.code OPTION_NOT_IN_PLAN: your plan lacks that feature. Upgrade or drop the option. - 429 + error.code RATE_LIMITED: too many requests this second. Cool down and retry. The trap to avoid: OPTION_NOT_IN_PLAN c

When it applies

Not specified by the original author.

Instructions

Never classify a Brave Search API failure by HTTP status alone: - 422 + error.code SUBSCRIPTIONTOKENINVALID: the key is wrong or revoked. Rotate the key. - 422 + error.code VALIDATION: a parameter is wrong (e.g. an invalid country code). Fix the parameter. - 400 + error.code OPTIONNOTINPLAN: your plan lacks that feature. Upgrade or drop the option. - 429 + error.code RATELIMITED: too many requests this second. Cool down and retry. The trap to avoid: OPTIONNOTIN_PLAN carries meta.component: "authentication", which looks like an auth failure but the key is fine. Code that treats every 422 as auth (or trusts meta.component) can burn working keys; one team burned their whole key ring on a bad --country value. Branch only on error.code, and log the full error body so the next failure is diagnosable.

Context: Web (surf-agent-skill, verified against the live API 2026-08-29): Brave Search API answers HTTP 422 for both a bad key and a bad parameter, so the status cannot tell them apart. Branch on error.code: SUBSCRIPTIONTOKENINVALID means the key is wrong; VALIDATION means a parameter is wrong; OPTIONNOTINPLAN (400) means your plan lacks the feature. The trap: OPTIONNOTINPLAN also carries meta.component "authentication" while the key is perfectly good, so branching on meta.component or on status burns a working key. The author reports a single --country zzz misclassification burned every key in the ring permanently, since key burns persist until the next calendar month.

Evidence

Web (surf-agent-skill, verified against the live API 2026-08-29): Brave Search API answers HTTP 422 for both a bad key and a bad parameter, so the status cannot tell them apart. Branch on error.code: SUBSCRIPTIONTOKENINVALID means the key is wrong; VALIDATION means a parameter is wrong; OPTIONNOTINPLAN (400) means your plan lacks the feature. The trap: OPTIONNOTINPLAN also carries meta.component "authentication" while the key is perfectly good, so branching on meta.component or on status burns a working key. The author reports a single --country zzz misclassification burned every key in the ring permanently, since key burns persist until the next calendar month. Resolved: Never classify a Brave Search API failure by HTTP status alone: - 422 + error.code SUBSCRIPTIONTOKENINVALID: the key is wrong or revoked. Rotate the key. - 422 + error.code VALIDATION: a parameter is wrong (e.g. an invalid country code). Fix the parameter. - 400 + error.code OPTIONNOTINPLAN: your plan lacks that feature. Upgrade or drop the option. - 429 + error.code RATELIMITED: too many requests this second. Cool down and retry. The trap to avoid: OPTIONNOTIN_PLAN carries meta.component: "authentication", which looks like an auth failure but the key is fine. Code that treats every 422 as auth (or trusts meta.component) can burn working keys; one team burned their whole key ring on a bad --country value. Branch only on error.code, and log the full error body so the next failure is Source: https://github.com/frederico-kluser/surf-agent-skill/blob/HEAD/references/brave-api.md

By @issueatlas · Version 1 · Exact version

Maintainer review

Checking maintainer review for this exact version…

A maintainer review records the library version checked. It does not assert that it is the latest upstream release. Reported outcomes are separate evidence.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_Jm_92bmqvGS0CkRIVgdetQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Brave Search API 422 is ambiguous: read error.code, not the status <span>— Vectle</span></a>

Brave Search API 422 is ambiguous: read error.code, not the status | Vectle