The provider add flags that sign in with OAuth, report quota, rewrite traffic, and read a provider's model catalog.
These flags extend provider add. They work in any crushrc, but they're mostly what provider plugins are made of. For the basic flags (--type, --base-url, --api-key, and so on) and for model add, see Provider & Model Commands.
Usage: provider add <id> [flags]OAuth flags: --oauth-kind string oauth or api_key (default oauth) --oauth-flow string auto, browser, or device (default auto) --oauth-issuer URL authorization server to discover endpoints from --oauth-client-id string OAuth client ID --oauth-client-secret string OAuth client secret (confidential clients) --oauth-scope string request a scope (repeatable) --oauth-refresh-scope string scope a refresh names instead (repeatable) --oauth-auth-url URL authorization endpoint --oauth-token-url URL token endpoint --oauth-device-url URL device authorization endpoint (RFC 8628) --oauth-redirect-uri URI loopback redirect URI the server registered --oauth-callback-port int loopback port for the browser flow --oauth-param key value extra authorization parameter (repeatable) --oauth-secret-basic bool send the client secret with HTTP Basic auth --oauth-token-header key value header sent to the token endpoint (repeatable) --oauth-token-encoding string form or json (default form)Quota flags: --usage-url URL endpoint reporting the quota left --usage-method string HTTP method for the quota call (default GET) --usage-body JSON request body for the quota call (default {}) --usage-groups PATH gjson path to the groups holding meters --usage-group-label string field naming each group (default displayName) --usage-meters PATH gjson path to the meters (default buckets) --usage-label string field naming each meter (default displayName) --usage-remaining string field with the fraction or amount left (default remainingFraction) --usage-spent-percent string field with the percent already spent (0-100) --usage-reset string field with the RFC 3339 reset time (default resetTime) --usage-title string label for a meter that carries none (default Remaining) --usage-window string field with a short meter tag (default window) --usage-model-group PREFIX GROUP model id prefix to group (repeatable)Gateway flags: --gateway-request JQ jq program rewriting each request --gateway-response JQ jq program rewriting each response --gateway-http1 bool speak HTTP/1.1 rather than negotiate HTTP/2Catalog flags: --catalog-url URL endpoint listing the provider's models --catalog-method string HTTP method for the catalog call (default GET) --catalog-body JSON request body for the catalog call (default {}) --catalog-program JQ jq program reading that listing into models --catalog-header key value header sent only with the catalog call (repeatable)OAuth providers
A provider authenticates with --api-key unless the --oauth-* flags declare a flow. Any --oauth-* flag marks the provider as one that signs in (unless --oauth-kind api_key says otherwise), which is what makes crush login <id> work for a provider Crush does not ship:
provider add example \ --type completions \ --base-url "https://api.example.com/v1" \ --oauth-issuer "https://auth.example.com" \ --oauth-client-id crush \ --oauth-scope openid \ --oauth-scope offline_access{ "providers": { "example": { "type": "completions", "base_url": "https://api.example.com/v1", "auth": { "issuer": "https://auth.example.com", "client_id": "crush", "scopes": ["openid", "offline_access"] } } }}Endpoints left blank are discovered from the issuer's well-known documents (RFC 8414). The browser flow (authorization code with PKCE and a loopback redirect) is the default, falling back to the device flow (RFC 8628) when no callback can be served. Pin one with --oauth-flow browser or --oauth-flow device. Tokens are persisted and refreshed like the built-in subscription providers, and the models the credential unlocks are discovered once the sign-in lands.
A provider that declares an OAuth flow is a sign-in candidate until crush login <id> stores its token: it appears in the model picker but is not treated as a configured provider, so Crush asks you to authenticate rather than selecting it with no credential.
Servers that need a fixed redirect, nonstandard endpoints, or an extra parameter such as audience are covered by --oauth-redirect-uri, --oauth-auth-url/--oauth-token-url/--oauth-device-url, and --oauth-param. Confidential clients whose server expects HTTP Basic auth set --oauth-secret-basic true. The issuer, client ID and secret, endpoint URLs, redirect URI, extra parameters, and token headers all go through variable expansion, so secrets can come from the environment rather than the plugin.
Some token endpoints need extra headers on every call, such as a tenant or an API version. --oauth-token-header KEY VALUE (repeatable) declares them. A server that takes JSON bodies instead of the RFC 6749 form encoding sets --oauth-token-encoding json; with JSON, the authorization-code exchange also carries the flow's state, which those servers expect, and a refresh repeats the authorization scopes unless --oauth-refresh-scope names others:
provider add example \ --type completions \ --base-url "https://api.example.com/v1" \ --oauth-token-header X-Tenant "example-tenant" \ --oauth-token-encoding json{ "providers": { "example": { "type": "completions", "base_url": "https://api.example.com/v1", "auth": { "token_headers": { "X-Tenant": "example-tenant" }, "token_encoding": "json" } } }}Each flag sets one field of the provider's auth object:
| Flag | JSON field |
|---|---|
--oauth-kind | kind |
--oauth-flow | flow |
--oauth-issuer | issuer |
--oauth-client-id | client_id |
--oauth-client-secret | client_secret |
--oauth-scope | scopes (array) |
--oauth-refresh-scope | refresh_scopes (array) |
--oauth-auth-url | authorize_url |
--oauth-token-url | token_url |
--oauth-device-url | device_auth_url |
--oauth-redirect-uri | redirect_uri |
--oauth-callback-port | callback_port |
--oauth-param | extra_params (object) |
--oauth-secret-basic | client_secret_basic |
--oauth-token-header | token_headers (object) |
--oauth-token-encoding | token_encoding |
Remaining quota
A plan that reports how much allowance is left can be read without any Crush code: declare where the report lives, and crush usage prints it.
provider add example \ --usage-url "https://api.example.com/v1/remaining-quota" \ --usage-method POST \ --usage-groups groups{ "providers": { "example": { "usage": { "url": "https://api.example.com/v1/remaining-quota", "method": "POST", "groups": "groups" } } }}$ crush usageExample Plan Standard Models · Weekly Limit Remaining: 1% used · resets in 6d 22h Standard Models · Five Hour Limit Remaining: 1% used · resets in 3h 57mThe response is walked with gjson paths. --usage-groups names the groups holding the meters (each contributing a label), --usage-meters names the meters inside them, and --usage-label / --usage-remaining / --usage-reset name the fields within each meter. Those three default to displayName, remainingFraction, and resetTime, and --usage-meters defaults to buckets, so the declaration above needs nothing else. For a response that is a single flat value, set --usage-meters . and name the field with --usage-remaining; --usage-title labels it. --usage-window names a field carrying a short tag for the meter (5h, weekly), which is what the header shows.
A remaining value of 1 or less is read as a share of the allowance, and anything larger as an amount, such as a credit balance. A plan that instead reports the other side of the same allowance (what has been spent) names that field with --usage-spent-percent, as a whole percentage from 0 to 100, and the meter shows its complement. The unit is in the flag name because the number alone cannot carry it: a plan 1% spent and a plan fully spent are both written as 1. The provider's credential (its login token or API key) and --extra-header values are sent with the request. --usage-url and --usage-body go through variable expansion.
The same figures appear in the UI while the model is in use: the header shows a compact ◆ 5h 99% · weekly 99% for the current model, and the sidebar spells the limits out with their refill times. When a plan reports different limits per model family, --usage-model-group PREFIX GROUP (repeatable) maps a model id to the group its allowance comes from, so the display shows the limits that apply rather than every limit on the plan:
provider add example \ --usage-url "https://api.example.com/quota" \ --usage-groups groups \ --usage-model-group fast "Fast models" \ --usage-model-group pro "Pro models"{ "providers": { "example": { "usage": { "url": "https://api.example.com/quota", "groups": "groups", "model_groups": { "fast": "Fast models", "pro": "Pro models" } } } }}A provider with one plan-wide allowance needs no mapping at all: every meter applies. With a mapping declared, a model id it does not cover shows nothing, because one family's limits beside another's model reads as a plan being spent when it is not.
Each flag sets one field of the provider's usage object:
| Flag | JSON field |
|---|---|
--usage-url | url |
--usage-method | method |
--usage-body | body (a string holding JSON) |
--usage-groups | groups |
--usage-group-label | group_label |
--usage-meters | meters |
--usage-label | label |
--usage-remaining | remaining |
--usage-spent-percent | spent_percent |
--usage-reset | reset |
--usage-title | title |
--usage-window | window |
--usage-model-group | model_groups (object) |
Gateway adapters
Some plans are served by a gateway whose wire format differs from the API the SDK speaks: a different envelope, different model naming, a differently framed stream. --gateway-request and --gateway-response declare that translation as jq programs, so the provider stays configuration and Crush stays provider-blind. A gateway needs both programs; with only one, it is skipped with a warning.
The request program receives
{"method": "POST", "url": "…", "headers": {}, "body": {}, "request_id": "…", "token": "…"}and returns any of url (the request is re-addressed, and the Host header with it), headers to set, drop_headers to remove, and body to replace:
provider add example \ --type messages \ --base-url "https://api.example.com" \ --gateway-request ' .body as $b | {url: "https://gateway.example.com/v1/generate", headers: {Authorization: ("Bearer " + .token)}, drop_headers: ["x-api-key"], body: {model: $b.model, requestId: .request_id, request: $b}}' \ --gateway-response 'if .event then [(.data.response // .data)] else (.body.response // .body) end'{ "providers": { "example": { "type": "messages", "base_url": "https://api.example.com", "gateway": { "request": ".body as $b | {url: \"https://gateway.example.com/v1/generate\", headers: {Authorization: (\"Bearer \" + .token)}, drop_headers: [\"x-api-key\"], body: {model: $b.model, requestId: .request_id, request: $b}}", "response": "if .event then [(.data.response // .data)] else (.body.response // .body) end" } } }}The response program runs once per reply: for a plain body it receives {status, headers, body, request_id, token} and returns the replacement body; for a server-sent event stream it receives {event: true, status, headers, data, final, request_id, token} and returns an array of replacement events, which may be empty to drop one or longer to append synthesized ones. final marks the last event, which means a rewritten stream trails the upstream by one event; events whose data is not JSON pass through untouched. An event's own name, when the stream carries one, is framing rather than data and is carried over verbatim, because a reader dispatches on it.
Both programs are compiled at load time, so a jq typo fails startup with the provider named rather than breaking a request later. Adapters are applied to messages-type providers and to the built-in gemini provider; declaring one for any other provider warns at load, and the adapter is not used.
Beyond jq itself the programs have two functions: sha256hex(s) returns the lowercase hex SHA-256 of a string, and uuid returns a fresh random RFC 4122 version 4 id. They exist because a program that signs a request, or stamps it with a per-request id, cannot do either in plain jq. Catalog programs speak the same dialect.
--gateway-http1 true stops the transport negotiating HTTP/2, which Go does by default against servers that offer it. Use it for a gateway that only works over HTTP/1.1.
The flags set the provider's gateway object: --gateway-request is request, --gateway-response is response, and --gateway-http1 is http1.
Model catalog
--discover-models reads the OpenAI-shaped /models listing, which reports only ids. A provider that publishes more than that (display names, context windows, which reasoning levels a model takes) can be read directly with --catalog-url and --catalog-program: the endpoint, and the jq program that turns its response into model objects. The field names belong to the provider, so they stay in the plugin. A catalog is read only for providers Crush doesn't ship, and only when the provider is enabled and has a --base-url.
The program receives the parsed listing as its input and returns an array of model objects (a single object is accepted too). An entry with no id is skipped. These are the fields a model object can carry:
| Field | Meaning |
|---|---|
id | model id, required |
name | display name |
context_window | context window in tokens |
default_max_tokens | default maximum output tokens |
reasoning.thinking | always, never, or toggleable |
reasoning.effort_levels | selectable effort levels, each {"value": "high", "display": "High"} |
reasoning.default_effort_level | the effort level used when none is picked |
capabilities.vision | whether the model accepts images |
max_attachments | maximum attachments per request |
pricing.input, pricing.output, pricing.cache_create, pricing.cache_hit | prices per 1M tokens |
provider add example --type messages --base-url "https://api.example.com" \ --catalog-url "/v1/models" \ --catalog-header X-Api-Version "2025-01-01" \ --catalog-program ' .data | map({ id, name: (.display_name // .id), context_window: (.max_input_tokens // 0), default_max_tokens: (.max_tokens // 0), reasoning: { thinking: (if .capabilities.thinking.supported then "toggleable" else "never" end), effort_levels: [.capabilities.effort // {} | to_entries[] | select((.value | objects | .supported) == true) | {value: .key, display: .key}] }, capabilities: {vision: (.capabilities.image_input.supported == true)} })'{ "providers": { "example": { "type": "messages", "base_url": "https://api.example.com", "catalog": { "url": "/v1/models", "headers": { "X-Api-Version": "2025-01-01" }, "program": ".data | map({id, name: (.display_name // .id), context_window: (.max_input_tokens // 0), default_max_tokens: (.max_tokens // 0), reasoning: {thinking: (if .capabilities.thinking.supported then \"toggleable\" else \"never\" end), effort_levels: [.capabilities.effort // {} | to_entries[] | select((.value | objects | .supported) == true) | {value: .key, display: .key}]}, capabilities: {vision: (.capabilities.image_input.supported == true)}})" } } }}A URL beginning with a slash is joined to the provider's --base-url; a full URL is fetched as given. --catalog-method POST sends --catalog-body, which defaults to {}: the envelope a gateway that serves its quota over POST typically serves its catalog over too. --catalog-header (repeatable) is sent with the catalog call only, which keeps a header one listing demands off the provider's other traffic. The provider's credential (its login token, or its API key when it has no login) is sent as a bearer automatically, and --extra-header values ride along as well.
Models the config declares are not replaced. A declared entry keeps every field it sets and adopts the rest from the listing, so pinning one model's default effort costs you nothing else about it:
provider add example --base-url "https://api.example.com" \ --catalog-url "/v1/models" --catalog-program '.data'model add example/big-model --reasoning-effort medium{ "providers": { "example": { "base_url": "https://api.example.com", "catalog": { "url": "/v1/models", "program": ".data" }, "models": [ { "id": "big-model", "reasoning": { "default_effort_level": "medium" } } ] } }}model add only works on a provider declared in the same file, so a model add that pins a plugin's model goes in that plugin, or after its own provider add line.
Booleans are the exception: a declaration can add a capability, not veto one, because false and "not stated" are the same value in config. Delete a model from the listing by not selecting it in the program.
The catalog is fetched at load, under a three-second budget shared with every provider's catalog, and its program is compiled then too: a jq typo fails startup naming the provider rather than leaving it without models. If the fetch fails, the provider keeps whatever models it declared.
The flags set the provider's catalog object: url, method, body (a string holding JSON), program, and headers (an object).
Pricing
Crush prices models from the catalog it ships and from the --price-input, --price-output, --price-cache-create, and --price-cache-hit flags on model add, in US dollars per 1M tokens. There is no pricing endpoint to fetch from: providers that serve a subscription often publish none at all, and their model ids are specific to that plan.
For a subscription, --flat-rate true is the accurate setting: Crush then skips per-token cost accumulation rather than reporting dollars that were never spent. If you still want nominal figures in the UI, declare them yourself:
provider add example --flat-rate true --usage-url "https://api.example.com/quota"model add example/code-1 --name "Code 1" --price-input 3 --price-output 15{ "providers": { "example": { "flat_rate": true, "usage": { "url": "https://api.example.com/quota" }, "models": [ { "id": "code-1", "name": "Code 1", "pricing": { "input": 3, "output": 15 } } ] } }}A plugin is Bash, so it can fetch a price list at load time and pass the flags:
# ~/.config/crush/plugins/example.shprice=$(curl -fsSL "https://example.com/prices/code-1.json" | jq -r .input)model add example/code-1 --name "Code 1" --price-input "$price"