On this page
React SDK
Typed config for React, straight from the edge
@betterconfigdev/react reads your published config into React with two hooks, keeps it fresh with cheap ETag revalidation, and generates TypeScript types from your project schema, so keys autocomplete and a typo is a type error.
npm install @betterconfigdev/react- React 18.2+ and 19
- Next.js App Router ready
- ESM + CJS, typed
- Node 20+ server entry
Overview
One package for every place your React code runs: the browser, server components, route handlers, and plain Node scripts.
- 01EditChange a value in the dashboard, the CLI, or through an AI agent over MCP.
- 02PublishEach environment's values are pushed to the edge read API as a versioned blob.
- 03ReadThe SDK fetches that blob with a read token and revalidates it by version.
- 04RenderHooks hand the values to your components, typed from your project schema.
The SDK only ever reads. It calls the public read API with a read token, caches the result in memory, and revalidates with the config's version as an ETag, so an unchanged config costs a bodyless 304. Published changes are typically live in under a minute, and a running app picks them up on its next refresh.
| Import | What it gives you |
|---|---|
| @betterconfigdev/react | BetterConfigProvider, useConfig, useConfigValue, useBetterConfigClient, plus everything in the server entry. Ships a "use client" directive. |
| @betterconfigdev/react/server | React-free: fetchConfig, fetchSchema, BetterConfigClient, BetterConfigError, the codegen helpers, and all types. Safe in server components, route handlers, edge runtimes, and Node. |
| betterconfig-typegen | A command that writes a .d.tsfor your project's keys. See Type generation. |
Install
npm install @betterconfigdev/react- Published on npm as @betterconfigdev/react. Upgrade by adding
@latestto the package name. - React
^18.2.0or^19.0.0is a peer dependency. Nothing else is pulled in. - Ships ESM and CommonJS builds with type declarations for both entries.
- The server entry runs on Node 20 or later and on edge runtimes with a global
fetch. The typegen command needs Node 20 or later.
Quickstart
You need a project slug, an environment key, and a read token. Create the token in your project under Settings → API tokens (or with betterconfig tokens create from the CLI).
- 1
Add your token to the environment.
.env.local# .env.local NEXT_PUBLIC_BETTERCONFIG_TOKEN=bc_your_environment_scoped_token - 2
Render the provider in your root layout. It stays a server component: the SDK's root entry is marked
"use client", so the provider becomes the client boundary on its own.app/layout.tsx// app/layout.tsx (a server component) import { BetterConfigProvider } from "@betterconfigdev/react"; export default function RootLayout({ children }: { children: React.ReactNode }) { return ( <html lang="en"> <body> <BetterConfigProvider token={process.env.NEXT_PUBLIC_BETTERCONFIG_TOKEN!} project="my-project" environment="prod" > {children} </BetterConfigProvider> </body> </html> ); } - 3
Generate types for your keys.
Terminalnpx betterconfig-typegen --project my-project --token bc_... --out src/betterconfig.d.ts - 4
Read values from any client component. The second argument is the fallback used until config loads, or when the key isn't set in this environment.
app/checkout-button.tsx// app/checkout-button.tsx "use client"; import { useConfigValue } from "@betterconfigdev/react"; export function CheckoutButton() { const enabled = useConfigValue("checkout.enabled", false); const label = useConfigValue("checkout.label", "Buy now"); if (!enabled) return null; return <button type="button">{label}</button>; }
Server-render real values
As written, the server renders fallbacks and the browser fetches after hydration. To render real values on the server with no client fetch, pass initialConfig. See Server-side reads and SSR.
The token ships to the browser
Anything you hand the provider ends up in your client bundle. Use an environment-scoped token and keep only config you'd be fine making public in that environment. Read Read tokens before you ship.
BetterConfigProvider
Creates one client for the subtree below it and shares it with every hook. Mount it once, as high as the config is needed.
| Prop | Type | Description |
|---|---|---|
| tokenrequired | string | A bc_ read token. Read-only, scoped to a project or one environment. |
| projectrequired | string | The project slug. |
| environmentrequired | string | The environment key, such as dev or prod. There is no default: new projects start with only dev, so the SDK never guesses. |
| refreshInterval | number | Poll cadence in milliseconds while at least one component is subscribed. Defaults to 0, which fetches once and then only on refresh(). Values under 10,000 are raised to 10,000. |
| initialConfig | SdkConfig | A config read elsewhere, usually on the server with fetchConfig. The client starts ready and skips its first fetch. Must match project and environment. |
| baseUrl | string | The read API origin. Defaults to https://api-public.betterconfig.dev. Trailing slashes are trimmed and path prefixes are kept, so a proxy at https://example.com/bc works. |
| fetch | FetchLike | A custom fetch for tests or proxies. Defaults to the global fetch. |
| client | BetterConfigClient | Pass a client you built yourself instead of the options above. Use one form or the other. |
| children | ReactNode | The part of your tree that reads config. |
- A missing
token,project, orenvironmentthrows aTypeErroron the first render, so an unset environment variable fails loudly instead of reading nothing. - An
initialConfigfor a different project or environment also throws, rather than serving the wrong values. - Polling only runs while hooks are subscribed. An unmounted provider holds no timers and needs no cleanup.
The client is fixed for the provider's lifetime
The provider builds its client once, on mount. Later prop changes are ignored, including a switch between inline options and client. To point at a different project or environment, give the provider a key so React mounts a fresh one.
<BetterConfigProvider
key={environment}
token={token}
project="my-project"
environment={environment}
>
{children}
</BetterConfigProvider>Bring your own client
Build a BetterConfigClient when you want to share one instance across roots, read it outside React, or pass a custom fetch. Functions and class instances can't cross from a server component to a client component, so in the App Router do this in a "use client" file.
"use client";
import { BetterConfigClient, BetterConfigProvider } from "@betterconfigdev/react";
const client = new BetterConfigClient({
token: process.env.NEXT_PUBLIC_BETTERCONFIG_TOKEN!,
project: "my-project",
environment: "prod",
refreshInterval: 60_000,
});
export function ConfigProvider({ children }: { children: React.ReactNode }) {
return <BetterConfigProvider client={client}>{children}</BetterConfigProvider>;
}Hooks
Both hooks subscribe through useSyncExternalStore, so they are safe with concurrent rendering and server rendering. Call them inside the provider or they throw.
useConfig()
Returns the full snapshot plus a refresh function. The first component to subscribe starts the first fetch.
| Field | Type | Description |
|---|---|---|
| status | "idle" | "loading" | "ready" | "error" | idle before the first fetch, loading during it, then ready or error. Once ready, it stays ready: later failures surface in error instead. |
| values | ConfigValues | Every key published to this environment. Empty until the first successful read. |
| version | number | null | The environment's config version. Increments on every publish. |
| fetchedAt | number | null | Server timestamp in milliseconds of the last full (200) read. A 304 leaves it unchanged. |
| error | BetterConfigError | null | The most recent failure. Cleared by the next successful read. |
| refresh | () => Promise<ConfigSnapshot> | Fetch now. Never rejects, and joins any request already in flight. |
"use client";
import { useConfig } from "@betterconfigdev/react";
export function ConfigStatus() {
const { status, version, error, refresh } = useConfig();
if (status === "error") {
return <button onClick={() => refresh()}>Retry ({error?.code})</button>;
}
return <span>{status === "ready" ? `Config v${version}` : "Loading..."}</span>;
}useConfigValue(key, fallback?)
Returns one value. Without a fallback you get undefineduntil config is ready, or when the key isn't set in this environment. With a fallback you get the fallback in those cases instead, typed as the key's value type.
// With generated types
const timeout = useConfigValue("api.timeoutMs"); // number | undefined
const retries = useConfigValue("api.retries", 3); // number
const theme = useConfigValue("theme", { accent: "green", radius: 8 });A component re-renders when the snapshot changes: a new version, a status change, or an error. Quiet polls that answer 304 keep the same snapshot object, so they cause no re-render at all.
useBetterConfigClient()
Returns the provider's BetterConfigClient for imperative access, for example client.get(key) inside an event handler without subscribing the component to updates.
BetterConfigClient
The framework-free engine behind the hooks. Use it directly in Node services, workers, scripts, or any UI library.
Its constructor takes the same options as the provider (see the table above). Import it from @betterconfigdev/react/server outside React.
import { BetterConfigClient } from "@betterconfigdev/react/server";
const client = new BetterConfigClient({
token: process.env.BETTERCONFIG_TOKEN!,
project: "my-project",
environment: "prod",
refreshInterval: 30_000,
});
// Subscribing starts the first fetch and, with refreshInterval, polling.
const unsubscribe = client.subscribe(() => {
const { status, version, error } = client.getSnapshot();
console.log(status, version, error?.code);
});
await client.refresh(); // never rejects; failures land in getSnapshot().error
const timeoutMs = client.get("api.timeoutMs", 5000);
// On shutdown
unsubscribe();
client.close();| Member | Description |
|---|---|
| subscribe(listener) | Calls listener on every snapshot change and returns an unsubscribe function. The first subscriber triggers the first fetch. Polling runs only while at least one listener is attached. |
| getSnapshot() | The current ConfigSnapshot: { status, values, version, fetchedAt, error }. |
| getServerSnapshot() | The snapshot as it was at construction. React uses it for server rendering and hydration. |
| refresh() | Fetches now and resolves with the new snapshot. Never rejects. Concurrent calls share one request, and a pending poll is re-armed from now so it doesn't fire right behind you. |
| get(key, fallback?) | Reads one value from the current snapshot, with the same typing and fallback rules as useConfigValue. |
| close() | Stops polling, aborts any request in flight, and drops all listeners. A closed client can't be reused: refresh() resolves with the last snapshot and sends nothing. |
Server-side reads and SSR
Import from @betterconfigdev/react/server in server components, route handlers, middleware, and scripts. The root entry carries a "use client"directive, and a server component can't call functions exported from a client module.
One-off reads with fetchConfig
fetchConfig makes a single read and resolves with the SdkConfig. Unlike the client, it throws: a BetterConfigError for API and network failures, or a TypeError when token, project, or environment is missing. It also accepts baseUrl, fetch, and an AbortSignal as signal.
import { BetterConfigError, fetchConfig } from "@betterconfigdev/react/server";
const config = await fetchConfig({
token: process.env.BETTERCONFIG_TOKEN!,
project: "my-project",
environment: "prod",
}).catch((error: unknown) => {
// Nothing has been published to this environment yet
if (error instanceof BetterConfigError && error.code === "not_found") return null;
throw error;
});
const timeoutMs = config?.values["api.timeoutMs"] ?? 5000;fetchSchemais its sibling for the project's key schema, the same call the typegen command makes. It takes a token and project but no environment.
SSR bootstrap with initialConfig
Read config on the server and hand it to the provider. The server HTML renders with real values, hydration matches it exactly, and the browser skips the initial fetch.
// app/layout.tsx
import { BetterConfigProvider } from "@betterconfigdev/react";
import { fetchConfig } from "@betterconfigdev/react/server";
const project = "my-project";
const environment = "prod";
export default async function RootLayout({ children }: { children: React.ReactNode }) {
// A failed server read falls back to a normal client-side fetch.
const initialConfig = await fetchConfig({
token: process.env.BETTERCONFIG_TOKEN!,
project,
environment,
}).catch(() => undefined);
return (
<html lang="en">
<body>
<BetterConfigProvider
token={process.env.NEXT_PUBLIC_BETTERCONFIG_TOKEN!}
project={project}
environment={environment}
initialConfig={initialConfig}
refreshInterval={60_000}
>
{children}
</BetterConfigProvider>
</body>
</html>
);
}- The browser's first refresh sends the server version as
If-None-Match, so unchanged config answers304. - With
initialConfigand norefreshInterval, the browser never fetches on its own. Values stay as rendered until you callrefresh(). - The server read can use a different token than the browser. Keep a project-scoped token in a server-only variable and give the browser an environment-scoped one.
- Every
fetchConfigcall is a metered read. Cache or revalidate the route the way you would any other data fetch.
Generated types cover both entries, so client.get() is typed on the server just like the hooks. fetchConfig returns the raw wire shape, where values is a Record<string, unknown>.
Refresh and caching
The defaults are deliberately frugal: every read is metered, so the SDK only asks when it has a reason to.
When the SDK fetches
- Once, on first use. The first subscribed component triggers a single read. Without a
refreshInterval, that is the only automatic fetch. - On demand.
refresh()fetches immediately, ignoring any backoff. Overlapping calls share one request. - On a schedule, if you opt in.
refreshIntervalpolls while at least one component is mounted and stops after the last one unmounts. The floor is 10 seconds, exported asMIN_REFRESH_INTERVAL_MS.
Revalidation by version
Every config response carries ETag: "v<version>". The client sends it back as If-None-Match, and an unchanged config answers 304 with no body. The snapshot object stays identical on a 304, so subscribed components don't re-render on quiet polls. A 304 still counts as a read.
Failures keep serving stale values
Once the client has loaded config, it never throws it away. A failed refresh keeps status: "ready" and the last good values, and records the failure in error. The next success, including a 304, clears it. Only a client that has never loaded reports status: "error".
After a failure, the next scheduled poll waits for the longer of your refreshInterval and a backoff:
| Failure | Backoff |
|---|---|
| Most failures | 1s, then 2s, 4s, 8s, and so on, capped at 60s. Resets after any success. |
| rate_limited | At least 60s, or longer when the server's Retry-After says so. |
| reads_limit_exceeded | 5 minutes between attempts. |
How fresh is fresh?
Published changes are typically live in under a minute. A running app then picks them up on its next refresh, so choose a refreshInterval that matches how quickly a change has to land. Config responses send Cache-Control: public, max-age=30, stale-while-revalidate=300. To pick up changes sooner without a tight poll, call refresh() at natural moments, such as when a tab regains focus.
Error handling
Every API and network failure is a BetterConfigError with a stable code.
Where errors show up
fetchConfigandfetchSchemathrow them.BetterConfigClient.refresh(),useConfig().refresh, and polling never reject. The error lands insnapshot.error.- Missing required options throw a plain
TypeErrorinstead, since that is a bug in your code rather than a runtime condition.
Codes
| code | HTTP | When |
|---|---|---|
| missing_token | 401 | No bearer token was sent. |
| invalid_token | 401 | The token is unknown or has been revoked. |
| forbidden | 403 | The token belongs to another project, or it is locked to a different environment. |
| not_found | 404 | Nothing has been published to this environment, or the environment key doesn't exist. |
| schema_not_published | 404 | Schema reads only: the project has no published schema yet. |
| rate_limited | 429 | More than 120 requests in a minute from one token or one IP. |
| reads_limit_exceeded | 429 | The project owner's account has used its monthly read cap. |
| bad_request | 400 | The query string was rejected, for example a missing project. |
| invalid_response | 200 | The API answered with a body the SDK couldn't parse. |
| server_error | 5xx | Any other unexpected status from the API. |
| network_error | none | The request never completed: offline, DNS, CORS, or aborted. |
Properties
| Property | Description |
|---|---|
| code | One of the codes above. |
| message | A readable sentence for logs. |
| status | The HTTP status, or null when no response arrived. |
| retryAfterMs | Parsed from Retry-Afterwhen present. Browsers can't read that header across origins, so expect null in client code. |
| cause | The underlying error, for network and parse failures. |
import { BetterConfigError } from "@betterconfigdev/react";
function errorMessage(error: unknown) {
if (!(error instanceof BetterConfigError)) return "Unexpected error";
switch (error.code) {
case "invalid_token":
case "forbidden":
return "Check the token and its environment scope";
case "rate_limited":
return `Slow down, retry in ${(error.retryAfterMs ?? 60_000) / 1000}s`;
case "reads_limit_exceeded":
return "Monthly read cap reached";
default:
return error.message;
}
}instanceof BetterConfigError works across the root and server entries and across ESM and CommonJS builds, so an error thrown by one bundle matches the class imported from another.
The SDK reads error bodies defensively. Most API errors are { "error": "<code>" }, but a rejected query returns validation details and an unexpected failure can be plain text. When the body has no known code, the SDK maps the HTTP status instead.
Type generation
Your project already knows every key's type. Typegen turns that schema into a declaration file, so values are typed with zero runtime cost.
With the SDK: betterconfig-typegen
The SDK ships a betterconfig-typegen command that authenticates with a read token. Any token for the project works, including an environment-scoped one, because the schema is project-wide.
npx betterconfig-typegen --project my-project --token bc_... --out src/betterconfig.d.ts| Flag | Env var | Description |
|---|---|---|
| -p, --project <slug> | BETTERCONFIG_PROJECT | Project slug. Required. |
| -t, --token <token> | BETTERCONFIG_TOKEN | A bc_ read token. Required. |
| -o, --out <path> | Output file. Defaults to betterconfig.d.ts. Missing folders are created. | |
| -e, --env <key> | BETTERCONFIG_ENV | Only for projects with no published schema: infer types from this environment's values. |
| --base-url <url> | BETTERCONFIG_BASE_URL | Read API origin, for proxies. |
| --module <name> | Module to augment. Repeatable. Defaults to @betterconfigdev/react and @betterconfigdev/react/server. | |
| -h, --help | Print usage. |
With the CLI: betterconfig typegen
The betterconfig CLI has the same command with one upgrade: it can use your login instead of a token. Signed in, it reads key types straight from the dashboard API, so it works even for projects without a published schema. Pass --token in CI and it behaves exactly like the SDK command.
# Uses your login (betterconfig login) and linked project
betterconfig typegen --out src/betterconfig.d.ts
# In CI, with a read token instead of a login
betterconfig typegen --project my-project --token $BETTERCONFIG_TOKENWhat you get
The generated file declares your keys once and augments the SDK's BetterConfigValuesinterface in both entries. Key descriptions become doc comments, and key names that aren't valid identifiers are quoted.
// Generated by `betterconfig typegen`. Do not edit.
// Project: my-project
// Schema from: 2026-11-09T12:00:00.000Z
export interface BetterConfigSchema {
/** Primary call to action color */
"feature.button.color": string;
"checkout.enabled": boolean;
limits: {
maxBatch: number;
};
"banner.slides": Array<string>;
}
declare module "@betterconfigdev/react" {
interface BetterConfigValues extends BetterConfigSchema {}
}
declare module "@betterconfigdev/react/server" {
interface BetterConfigValues extends BetterConfigSchema {}
}useConfigValue("feature.button.color"); // string | undefined
useConfigValue("limits"); // { maxBatch: number } | undefined
useConfigValue("checkout.enabled", false); // boolean
useConfigValue("typo.key"); // type error| Key type | TypeScript |
|---|---|
| string | string |
| number | number |
| boolean | boolean |
| array of T | Array<T> |
| object with fields | { field: T; ... } |
| free-form JSON | unknown |
- Values stay optional (
| undefinedwithout a fallback) because any environment may not have a key set. - Before you generate types, keys are plain
stringand values areunknown. - Put the file anywhere your
tsconfig.jsonincludes, and commit it.
Keep it current
Re-run typegen whenever keys change. A predev and prebuild script does it for you, with the project and token supplied through BETTERCONFIG_PROJECT and BETTERCONFIG_TOKEN.
{
"scripts": {
"typegen": "betterconfig-typegen --out src/betterconfig.d.ts",
"predev": "npm run typegen",
"prebuild": "npm run typegen"
}
}Projects without a published schema
Projects created before schema publishing get their schema on the next key edit. Until then the token-based command stops with schema_not_published. Edit any key in the dashboard to publish it, sign in and use betterconfig typegen, or pass --env <key>to infer types from that environment's values. Inference is lossy (empty arrays become Array<string>, null becomes string, and only the first array item is sampled), and the file says so in its header.
Read tokens
Every SDK read authenticates with a bc_ token. Tokens can read config. They can never change it.
Creating a token
Project owners create tokens under Settings → API tokens in the dashboard, or from the CLI. The full token is shown once, at creation. After that only its prefix is visible, so store it in your secrets manager right away. Revoking a token makes the read API reject it.
betterconfig tokens create web-prod --env prodProject-scoped or environment-scoped
| Scope | Config reads | Schema reads |
|---|---|---|
| All environments | Any environment in the project. | Yes |
| One environment | Only that environment. Any other returns 403 forbidden. | Yes |
The schema endpoint is open to both scopes because it lists key names, types, and descriptions for the whole project, never values.
What's safe to ship to a browser
A token in client code is public: anyone can lift it from your bundle and read everything its scope allows. Decide with that in mind.
- Default to the server. Read config in server components, route handlers, or your backend, and keep tokens out of the browser entirely.
- If a browser needs live config,give it an environment-scoped token for that one environment, and store only values you'd be comfortable publishing there: feature flags, UI copy, limits, and toggles.
- Never put secrets in config a browser reads. API keys, credentials, and internal URLs belong in a server-only environment and behind a server-only token.
- Keep project-scoped tokens server-side. They read every environment, including production.
- A leaked token spends your quota.Reads count against the project owner's monthly cap, so revoke and replace a token you no longer trust.
Limits
Two limits apply to reads. Both answer 429, and the SDK backs off from both on its own.
Rate limit
The read API allows 120 requests per minute per token and, separately, per client IP. Past that it returns 429 rate_limited with Retry-After: 60. The limiter is tracked per edge location, so treat it as abuse protection rather than an exact budget. With the 10 second polling floor, one client stays far below it.
Server-side reads all come from your server's IP, so a server that calls fetchConfig on every request hits the limit at around two requests per second. Cache server reads, or keep one long-lived BetterConfigClient per process and read from its snapshot.
Monthly read cap
Every successful request to /v1/config is a metered read, 304revalidations included. Reads are summed across every project the owner owns and counted against the owner's plan:
| Plan | Reads per month |
|---|---|
| Free | 200,000 |
| Pro | 2,000,000 |
| Ultra | 200,000,000 |
This is a hard cap. Once an account is over it, every config read for that owner's projects returns 429 reads_limit_exceeded until the owner upgrades or the next month begins. Usage is checked every 15 minutes, so the block can start a few minutes after the line is crossed. Upgrading lifts it right away.
What your app sees when blocked
A client that already loaded config keeps serving its last values, with error.code set to reads_limit_exceeded, and retries every 5 minutes. A client that never loaded reports status: "error", so always pass fallbacks for values your UI can't live without.
Schema reads for typegen are not metered and are never blocked by the cap. Owners can watch usage under Settings → Usage and compare plans on the billing page.
HTTP API reference
The SDK is a thin layer over two endpoints on https://api-public.betterconfig.dev. Call them directly from any language.
Both take Authorization: Bearer <token>. CORS is open to every origin for GET, allows the Authorization, If-None-Match, and Content-Type request headers, and exposes ETag to scripts.
GET /v1/config
| Query | Type | Description |
|---|---|---|
| project | string | Project slug. Required. |
| env | string | Environment key. Defaults to prod when omitted. The SDK always sends it. |
| etag | string | Optional stand-in for If-None-Matchwhere you can't set headers. Accepts "v12", v12, or 12. |
curl "https://api-public.betterconfig.dev/v1/config?project=my-project&env=prod" \
-H "Authorization: Bearer $BETTERCONFIG_TOKEN" \
-iHTTP/2 200
content-type: application/json
etag: "v12"
cache-control: public, max-age=30, stale-while-revalidate=300
{
"projectSlug": "my-project",
"environmentKey": "prod",
"version": 12,
"fetchedAt": 1762689600000,
"values": {
"checkout.enabled": true,
"api.timeoutMs": 5000,
"limits": { "maxBatch": 50 }
}
}valuesholds every key set in the environment.versionis the environment's config version, andfetchedAtis the server time of the read in milliseconds.ETagis always"v<version>". Send it asIf-None-Matchto get304 Not Modifiedwhile nothing has changed.
curl "https://api-public.betterconfig.dev/v1/config?project=my-project&env=prod" \
-H "Authorization: Bearer $BETTERCONFIG_TOKEN" \
-H 'If-None-Match: "v12"' \
-i
# HTTP/2 304 (empty body) while version 12 is still currentGET /v1/schema
Returns the project's key schema, the input to typegen. Takes only project, accepts tokens of either scope, sends Cache-Control: no-store, and isn't metered. Projects without a published schema get 404 schema_not_published.
curl "https://api-public.betterconfig.dev/v1/schema?project=my-project" \
-H "Authorization: Bearer $BETTERCONFIG_TOKEN"{
"projectSlug": "my-project",
"generatedAt": 1762689600000,
"keys": [
{
"key": "limits",
"typeDef": {
"kind": "object",
"fields": { "maxBatch": { "kind": "number" } }
},
"description": null
},
{
"key": "banner.slides",
"typeDef": { "kind": "array", "items": { "kind": "string" } },
"description": "Homepage carousel copy"
}
]
}type ConfigType =
| { kind: "string" }
| { kind: "number" }
| { kind: "boolean" }
| { kind: "array"; items: ConfigType }
| { kind: "object"; fields: Record<string, ConfigType> };Errors
Errors are JSON with an error code from the error table. Two exceptions: a malformed query returns 400 with validation details, and an unexpected server failure may answer 500 with a plain-text body. Checks run in this order: rate limit, query, token, token scope, read cap, then whether config exists.
HTTP/2 429
cache-control: no-store
{ "error": "reads_limit_exceeded" }