feat(models): declare request APIs per preset

Bind API support and preference to the preset's provider and model. Carry the
API declaration through factory selection, fallback chains, hot reload and
WebUI persistence. Use Copilot endpoint metadata for automatic routing and
keep reasoning replay and compaction defaults in provider capability profiles.

Consolidate Responses follow-ups from #5906, #5935, #6020, #6051 and #5834;
acknowledge equivalent contributions in #6105 and #5863.

Co-authored-by: Parman Mohammadalizadeh <prmma23@gmail.com>
Co-authored-by: Lanre Shittu <136805224+Shizoqua@users.noreply.github.com>
Co-authored-by: kkkhoo <128304090+kkkhoo@users.noreply.github.com>
Co-authored-by: pei711 <199601925+pei711@users.noreply.github.com>
Co-authored-by: Steven Huang <134844631+remote-controlled-man@users.noreply.github.com>
Co-authored-by: Louis Yue <179701714+selfucker@users.noreply.github.com>
Co-authored-by: iuiuiu <92971770+iuiu-py@users.noreply.github.com>
This commit is contained in:
authored and chengyongru committed 2026-10-10 01:33:02 +08:00
1 parent 3c866d63ac
commit b5808e47de
23 files changed
+738 -63

No files matched your search

+28 -1
View File
@@ -316,7 +316,7 @@ Tracing covers the providers that go through nanobot's OpenAI-compatible client
<details>
<summary><b>OpenAI</b></summary>
By default, OpenAI uses `apiType: "auto"`: nanobot calls Chat Completions normally and routes GPT-5/o-series or explicit `reasoningEffort` requests through the Responses API when useful. You can force a specific API surface:
Without a preset API declaration, direct OpenAI uses `apiType: "auto"`: nanobot calls Chat Completions normally and routes GPT-5/GPT-6/o-series or explicit `reasoningEffort` requests through Responses. Prefer [preset API declarations](#preset-request-api) to select an API for each model and endpoint. The legacy provider-wide default remains available:
```json
{
@@ -1460,11 +1460,38 @@ Older configs may still contain a `label` inside a preset. It is accepted when l
| `contextWindowTokens` | Context window size used by prompt building and consolidation decisions. |
| `temperature` | Sampling temperature. |
| `reasoningEffort` | Optional reasoning/thinking setting. Provider support varies. |
| `api` | Optional supported APIs and preferred API for this model at the configured endpoint. |
`default` is reserved and always means the implicit preset built from direct `agents.defaults.*` fields; do not define `modelPresets.default`. Use `/model default` to switch back to those direct fields in an existing config.
Set `agents.defaults.modelPreset` to choose the preset followed by sessions that have no saved model selection. When `modelPreset` is `null` or omitted, such sessions follow the implicit `default` preset from direct `agents.defaults.*` fields. `/model <preset>` saves an override in the current session, so its future turns keep that preset across process restarts while other sessions remain unchanged. The command does not write the selection back to `config.json`.
### Preset request API
Declare API support in the preset for OpenAI-compatible providers, including custom gateways, and GitHub Copilot. Credentials and endpoint URLs stay in the provider. Two presets sharing a provider can select different APIs.
```json
{
"modelPresets": {
"gatewayReasoning": {
"provider": "companyProxy",
"model": "gpt-6-luna",
"reasoningEffort": "high",
"api": {
"supportedApis": ["responses"],
"preferredApi": "responses"
}
}
}
}
```
`supportedApis` is a nonempty list containing `chat_completions`, `responses`, or both. `preferredApi` must belong to that list; when omitted, it defaults to the first entry. A Responses-only preset never falls back to Chat Completions. Declare both APIs with `preferredApi: "responses"` to allow Chat fallback for classified Responses compatibility errors. Other failures retain their normal error handling. Native hosted search uses Responses when it is supported by the preset.
Omit `api` or set it to `null` for automatic routing. An explicit declaration overrides provider API defaults, including legacy `providers.openai.apiType`. Automatic Copilot routing uses the account's last successfully discovered `supported_endpoints` when available; other automatic routes use registry defaults. Custom gateways default to Chat Completions until Responses support is declared. Protocol behavior such as reasoning replay and native compaction remains provider-owned; declaring Responses support does not enable OpenAI-native compaction on a custom gateway.
In the WebUI, open **Settings → Models → a preset → Request API** to choose automatic routing, either API, or Responses with Chat fallback. Changing a preset's model or provider resets its API declaration to automatic unless the same update supplies a new declaration. Each fallback preset retains its own declaration. Legacy direct `agents.defaults.api` and inline fallback `api` values are preserved when converting to named presets.
### Model Fallbacks
`agents.defaults.fallbackModels` defines an ordered failover chain for the active model configuration. The primary model is still selected by `agents.defaults.modelPreset` or, in older configs, by the implicit `default` preset from direct `agents.defaults.*` fields.
@@ -70,6 +70,7 @@ nanobot agent -m "Hello!"
- Use a placeholder key such as `EMPTY` only when the endpoint requires a
non-empty key but does not validate it.
- Leave `apiType` unset for OpenAI-compatible custom endpoints.
- For models requiring Responses, declare `api.supportedApis: ["responses"]` in their [model preset](../configuration.md#preset-request-api), or select Responses in the WebUI preset editor.
## Security notes
+2 -2
View File
@@ -353,9 +353,9 @@ Arbitrary custom provider names are OpenAI-compatible only; they do not use the
}
```
`providers.openai.apiType` may be set when you need to force a specific OpenAI API surface. Other providers reject `apiType`; leave it unset outside `providers.openai`. Replace the model with a model ID available to your OpenAI account. Direct OpenAI Responses, OpenAI Codex, Azure OpenAI Responses, and eligible GitHub Copilot models share [opaque Responses state retention](./configuration.md#responses-state-and-compaction); native compaction is enabled only where the backend supports it. The WebUI exposes provider-native switches for OpenAI web search, Codex Fast mode, DeepSeek web search, and Grok X Search. These switches write the corresponding raw provider request fields under `extraBody`.
Use [preset API declarations](./configuration.md#preset-request-api) to choose Chat Completions or Responses for each model and endpoint. The legacy `providers.openai.apiType` remains a provider default for presets without a declaration; other providers reject provider-level `apiType`. Replace the model with a model ID available to your account. Direct OpenAI Responses, OpenAI Codex, Azure OpenAI Responses, and eligible GitHub Copilot models share [opaque Responses state retention](./configuration.md#responses-state-and-compaction); native compaction is enabled only where the backend supports it. The WebUI exposes provider-native switches for OpenAI web search, Codex Fast mode, DeepSeek web search, and Grok X Search. These switches write the corresponding raw provider request fields under `extraBody`.
DeepSeek is the model-level exception in the OpenAI-compatible provider: `deepseek-v4-flash` and `deepseek-v4-pro` automatically use DeepSeek's native Responses API. Its native `web_search` tool is enabled by default and shows its lifecycle in WebUI chat activity; set `providers.deepseek.extraBody.tools` to `[]` to disable it.
DeepSeek's `deepseek-v4-flash`, `deepseek-v4-pro`, and `deepseek-v4-flash-vision-exp` automatically use its native Responses API. Its native `web_search` tool is enabled by default and shows its lifecycle in WebUI chat activity; set `providers.deepseek.extraBody.tools` to `[]` to disable it. OpenCode Go's `muse-spark-1.2-contributor` and `muse-spark-1.3-contributor` also use Responses by default.
### Custom OpenAI-Compatible Endpoint