# Configure

Every setting of rungent and where it lives, in code, in rungent serve's environment or on the admin's Model settings page, and which one wins. Then the settings you tune most, models and thinking, instructions, limits, search sources and the names agents see.

rungent reads its settings from one of three places. An embedded rungent takes them as options of
`createRungent({...})` ([JavaScript](javascript.md)). `rungent serve`, beside an API in any other
language, reads the same settings from `RUNGENT_*` environment variables ([Deploy](deploy.md)).
And admins change the models, and only the models, at run time on a Model settings page.

## Where each setting lives

| Setting | In code, `createRungent` | With `rungent serve` |
|---|---|---|
| **Public URL** of rungent, the assertion's `iss`. Required. | `url` | `RUNGENT_URL` |
| **Your product's origin**, the assertion's `aud`. Required. | `host.origin` | `RUNGENT_HOST_ORIGIN` |
| **Your OpenAPI 3.1 document**, a path or URL, fetched with each user's credential. | `host.openapi` (required) | `RUNGENT_HOST_OPENAPI`, default `/api/openapi.json` |
| **Where rungent reaches your API**, when not through the public origin. | `host.fetch` (in the process), `host.baseUrl` | `RUNGENT_HOST_BASE_URL` |
| **Signing key**, rungent's private Ed25519 JWK with a `kid` ([Keys and rotation](acting-as-the-user.md#keys-and-rotation)). Required. | `signingKey` | `RUNGENT_SIGNING_KEY` |
| **Secret**, 32 bytes or more, that seals the model API keys admins save. Required. | `secret`; a list rotates it | `RUNGENT_SECRET`, and `RUNGENT_PREVIOUS_SECRET` while rotating |
| **Storage** for conversations, approvals and settings. Required. | `store` ([Choose a store](javascript.md#choose-a-store)) | `RUNGENT_DATABASE_URL`, `postgres://…` or `sqlite:<path>` |
| **Models and thinking**, `{ chain, thinking? }`. Admins also change them at run time, on the Model settings page or with `PUT /rungent/v0/settings` ([below](#choose-models)). | `models` (required) | `RUNGENT_MODELS`, the same object as JSON |
| **The assistant's name.** Default `Assistant`. | `name` | `RUNGENT_NAME` |
| **Instructions**, product facts added to the system prompt ([below](#tell-the-assistant-about-your-product)). | `instructions` | `RUNGENT_INSTRUCTIONS` |
| **Limits** of a run ([below](#limit-a-run)). | `limits` | `RUNGENT_MAX_STEPS` |
| **A prefix** for every route, when rungent is served below a path. | `basePath` | `RUNGENT_BASE_PATH` |
| **Search sources**, such as your docs ([below](#add-search-sources)). | `sources` | `RUNGENT_KNOWLEDGE_DIR`, `RUNGENT_KNOWLEDGE_BASE_URL` |
| **Your product's name and summary** in `/skill.md` and `/llms.txt` for signed-out callers, when your OpenAPI needs a sign-in. | `product` | `RUNGENT_PRODUCT_NAME`, `RUNGENT_PRODUCT_SUMMARY` |
| **The skill's name and guide** ([below](#name-the-skill-and-the-cli)). | `skill.name`, `skill.guide` | `RUNGENT_SKILL_NAME`, `RUNGENT_SKILL_GUIDE` |
| **The CLI the documents name** ([below](#name-the-skill-and-the-cli)). | `skill.cli` | `RUNGENT_CLI_COMMAND`, `RUNGENT_CLI_PACKAGE`, `RUNGENT_CLI_INSTALL` |
| **What MCP clients receive** on `initialize`. Default: the skill guide. | `mcp.instructions` | `RUNGENT_MCP_INSTRUCTIONS` |
| **OAuth issuers** advertised to MCP clients ([Sign in with OAuth](surfaces.md#sign-in-with-oauth)). | `mcp.authorizationServers` | `RUNGENT_MCP_AUTHORIZATION_SERVERS`, comma-separated |
| **Your API's public keys** for `Rungent-Host-Assertion` ([HTTP API](http-api.md#host-assertions)). | `hostKeys` | `RUNGENT_HOST_KEYS`, a JSON array of JWKs |
| **The listening port.** Default 8080. | your server's | `PORT` |

`RUNGENT_INSTRUCTIONS`, `RUNGENT_SKILL_GUIDE` and `RUNGENT_MCP_INSTRUCTIONS` take a file as
`@/path/to/file`. Only `rungent serve` reads `RUNGENT_*` variables; an embedded host passes values
from its own configuration, under any names it likes. The dock's own settings (language, theme,
your forms, suggestions, uploads) are props of `RungentProvider`, on
[JavaScript](javascript.md#props-that-matter).

### Which one wins

Everything except the models is read once, when `createRungent` is called or `rungent serve`
starts; change it in code or in the environment and deploy. The models are the defaults: once an
admin saves models on the settings page, the saved chain and thinking policy replace the
configured ones as a whole, for every user, until an admin presses **Reset to defaults** (`DELETE
/rungent/v0/settings`), and the configured models apply again.

## Choose models

rungent calls models through a **chain**: endpoints tried in order. When the first is out of credit
or rate-limited, the same turn goes on with the next, and the user sees at most "Model busy,
retrying".

```ts
createRungent({
  // ...
  models: {
    chain: [
      { id: 'qwen-flash', provider: 'dashscope', model: 'qwen3.7-flash', apiKey: process.env.DASHSCOPE_API_KEY, vision: true },
      { id: 'deepseek-flash', provider: 'dashscope', model: 'deepseek-v4.1-flash', apiKey: process.env.DASHSCOPE_API_KEY, vision: true },
    ],
  },
});
```

This is the setup we recommend: Qwen 3.7 Flash, then DeepSeek V4.1 Flash on the same DashScope
key when Qwen is busy, both reading images, thinking off until a user switches it on
([below](#let-users-switch-thinking-on)). In our measurements on four products, Flash followed
tool rules best and was the cheapest; larger models (Qwen 3.7 Plus, Qwen 4 Max) wrote their
deliberation into answers or opened forms nobody asked for, at ten to fifty times the cost. A
fallback from another vendor keeps answering when one model's capacity is throttled.
With `rungent serve`, `RUNGENT_MODELS` holds the same object as JSON:

```bash
RUNGENT_MODELS='{"chain":[{"id":"qwen-flash","provider":"dashscope","model":"qwen3.7-flash","apiKey":"sk-…","vision":true},{"id":"deepseek-flash","provider":"dashscope","model":"deepseek-v4.1-flash","apiKey":"sk-…","vision":true}]}'
```

Without `RUNGENT_MODELS` the chain is empty, and runs fail until an admin saves one.

| Field | What it is |
|---|---|
| `id` | Required, unique in the chain, 1 to 64 characters. Saved settings keep an endpoint's key by it. |
| `provider` | `dashscope` (Alibaba Cloud Model Studio: Qwen), `openai-compatible` (any OpenAI-style chat API: DeepSeek, vLLM, LiteLLM), `openai` or `anthropic`. |
| `model` | The provider's model id. |
| `baseURL` | Required for `openai-compatible`. `dashscope` defaults to the Beijing region, `https://dashscope.aliyuncs.com/compatible-mode/v1`; set it for another region, such as `https://dashscope-intl.aliyuncs.com/compatible-mode/v1` (Singapore). For `openai` and `anthropic`, a proxy or gateway. |
| `apiKey` | The provider's key. Without it, `openai` and `anthropic` read `OPENAI_API_KEY` and `ANTHROPIC_API_KEY`. |
| `vision` | The model reads images. Turns with images go to these endpoints first; others get a note in place of each image. |
| `temperature`, `maxOutputTokens` | Sent with every call to this endpoint. |
| `cooldownSeconds` | `{ quota?, rateLimit?, error? }`: how long a failing endpoint rests ([When a model fails](#when-a-model-fails)). |
| `timeoutSeconds` | `{ firstToken?, idle? }`: how long a call waits for the model's first output (default 20 s, connecting included) and then between outputs (60 s). Raise `firstToken` for a model that thinks or reads long prompts before it streams. |
| `providerOptions` | Passed to the provider with every call, keyed by provider name, such as `{ 'openai-compatible': { top_k: 20 } }`. `dashscope` endpoints use the key `openai-compatible`. |
| `thinking` | `{ on, off }`: the provider options that switch the model's reasoning on and off. `dashscope` has Qwen's built in. See [Let users switch thinking on](#let-users-switch-thinking-on). |

Embedded, an entry may also be any AI SDK language model, `{ id, languageModel }`, such as
Workers AI through `agents/models/ai-sdk`. It exists only in code; the settings show it read-only.

### When a model fails

A `408`, `5xx`, network error or unusable answer is retried on the same endpoint, up to 4
attempts. An endpoint that stalls (no output within `timeoutSeconds`) is left at once for the next
one, and retried only when it is the last one left. Any other failure, and the last retry, moves
the step to the next endpoint, and the failing one rests:

| Failure | Rests for | `cooldownSeconds` key |
|---|---|---|
| Out of quota: `402`, an answer that mentions quota, or a provider's quota code (DashScope `401008`, Workers AI `4006` when the daily free neurons are used up) | 6 hours | `quota` |
| Rate limited: `429` | 60 seconds | `rateLimit` |
| Anything else | 5 minutes | `error` |

When every endpoint rests, the run ends with `model_unavailable`; a run that outlasts
`limits.runTimeoutSeconds` ends with `timeout`. Rests live in one process. A text-only model first
and a vision model further down keeps ordinary turns cheap and still reads the screenshots users
attach.

Workers AI's free neurons are counted per Cloudflare account and per day (reset at 00:00 UTC):
every Worker and test run on the account draws from the same 10,000. Once they are used up, the
Workers AI endpoint rests for `quota` and the next endpoint answers; set `cooldownSeconds.quota`
if you want it tried again sooner.

### Let users switch thinking on

Reasoning models answer harder questions better but take about twice as long, and on create
tasks they can do worse: on one product, thinking lowered create success and doubled latency.
The chain's `thinking` policy decides whether runs think and whether users may choose:

```ts
models: {
  chain: [/* ... */],
  thinking: { default: 'off', userSwitch: true },
}
```

| Field | What it is |
|---|---|
| `default` | `'on'` or `'off'`: what a run does when the user has not chosen. Default `'off'`. |
| `userSwitch` | Users may switch thinking per run. Default `true`. When `false`, every run follows `default` and the user's choice is ignored. |

Unset, the policy is off with the switch for users, which is what we recommend. A run that
thinks uses each model's `on` options, every other call its `off` options, including routing to a
form, host jobs (`/generate`) and runs that finish a deferred task. What a thinking model writes
streams into the run's trace as its reasoning.

A `dashscope` model already knows Qwen's switch (`enable_thinking`). Give any other model that can
think its `on` and `off` provider options, merged over `providerOptions` on each call:

| Model | `on` | `off` |
|---|---|---|
| Tencent Hunyuan on TokenHub (`openai-compatible`) | `{ 'openai-compatible': { thinking: { type: 'enabled' } } }` | `{ 'openai-compatible': { thinking: { type: 'disabled' } } }` |
| `anthropic` | `{ anthropic: { thinking: { type: 'enabled', budgetTokens: 4000 } } }` | `{ anthropic: { thinking: { type: 'disabled' } } }` |
| `openai` reasoning models | `{ openai: { reasoningEffort: 'medium' } }` | `{ openai: { reasoningEffort: 'none' } }` (`'minimal'` on older models) |

A model with neither gets its `providerOptions` either way and never thinks on request. Once
some model of the chain can think, `GET /rungent/v0/info` answers the policy,
`thinking: { default, userSwitch }`, and `null` before. The dock shows its **Think** switch when
`userSwitch` is true; what users see is on [Use the assistant](use-the-assistant.md#think-before-answering).

### Let admins change the chain

Render `ModelSettings` from `@rungent/react` on a page only admins reach. Admins add,
remove and reorder endpoints, set each one's thinking options as JSON, and set the thinking
policy in its Thinking section (whether runs think, and whether users may switch); a key is
write-only, and **Reset to defaults** goes back to the models you configured. Saving needs the
`rungent:admin` scope in the user's [identity](acting-as-the-user.md#who-the-user-is), checked on
the server. The same is `GET`, `PUT` and `DELETE /rungent/v0/settings`
([HTTP API](http-api.md#settings)). Saved keys are sealed with `secret` before they reach the
database.

## Tell the assistant about your product

`instructions` adds product facts the API does not say to the system prompt: a string, or a
function of the user's identity, called for each run.

```ts
createRungent({
  // ...
  name: 'Console Assistant',
  instructions: (identity) =>
    `Servers are billed by the hour, and stopped servers only for storage. The user works in organization ${identity.tenant}.`,
});
```

With `rungent serve`, `RUNGENT_INSTRUCTIONS` holds the text, or `@/etc/rungent/instructions.md`
reads it from a file. Keep it short: the catalog already tells the model what each operation does.

## Limit a run

`limits` is `{ maxSteps, contextTokens, runTimeoutSeconds }`, by default 16 model steps per run,
a context of 128 000 tokens, and 600 seconds. A run that needs more steps ends with `max_steps`;
one that takes longer ends with `timeout`. `rungent serve` sets the steps with
`RUNGENT_MAX_STEPS`; the other two keep their defaults there.

## Add search sources

Your `role: search` operations are search sources without any setting. Your docs are one more
source: with `rungent serve`, `RUNGENT_KNOWLEDGE_DIR` and `RUNGENT_KNOWLEDGE_BASE_URL` index a folder
of Markdown at start; in code, `sources` takes a knowledge source that can also choose which docs
each user sees. Both are on [Search and knowledge](search.md#add-your-docs).

## Name the skill and the CLI

`/skill.md` and `/llms.txt` tell agents how to use your product, and which CLI to install. By
default they name `rungent-cli` from `@rungent/cli`. Name your [branded CLI](surfaces.md#a-cli-with-your-name)
and put a hand-written guide first:

```ts
createRungent({
  // ...
  skill: {
    name: 'acme-console',
    guide: '…a hand-written guide placed first…',
    cli: { command: 'acme', package: '@acme/cli' },
  },
});
```

`cli.install` takes a free-form install line instead of a package, and wins over it. With
`rungent serve`, set `RUNGENT_SKILL_NAME`, `RUNGENT_SKILL_GUIDE` (text or `@path`), and
`RUNGENT_CLI_COMMAND` with `RUNGENT_CLI_PACKAGE` or `RUNGENT_CLI_INSTALL`. Without a `name`, the
skill is named after your product, else your host's first hostname label. MCP clients receive the
guide as their instructions unless `mcp.instructions` says otherwise.

## Where to go next

[Deploy](deploy.md) runs rungent with these settings in production.
