Providers and Thinking
Provider configuration selects protocol, credentials, model ID, and optional reasoning parameters. OpenAI supports a compatible base URL; Anthropic uses its own message format and requires extended-thinking state preservation. CodeN does not probe service capabilities, so verify custom-endpoint compatibility with real requests.
OpenAI Configuration
Section titled “OpenAI Configuration”Minimal configuration
Section titled “Minimal configuration”export CODEN_OPENAI_API_KEY=sk-...codenopenai is the default provider with model gpt-5-mini. Overrides:
export CODEN_MODEL=gpt-5-minicoden --model gpt-5-mini "your task"Compatible endpoints
Section titled “Compatible endpoints”export CODEN_OPENAI_API_KEY=sk-...export CODEN_OPENAI_BASE_URL=https://api.example.com/v1coden --model your-model-id "your task"CODEN_OPENAI_BASE_URL is consumed directly by the OpenAI SDK; any SDK-compatible endpoint works, but CodeN maintains no model capability allowlist and sends parameters as-is.
Request shape
Section titled “Request shape”- Uses the streaming
chat.completionsAPI withstream_options.include_usagefor usage. - Tools are passed as OpenAI function calling (
type: "function", name/description/JSON Schema). max_completion_tokensof every request equalsreservedOutputTokens(default 8192).- The SDK’s internal
maxRetriesis 0: retries are owned by the agent loop (up to 3 exponential backoffs; see Agent Loop).
Thinking parameter
Section titled “Thinking parameter”--thinking levels map to reasoning_effort; off maps to minimal (shown as off→minimal), and minimal/low/medium/high map to the same-named values. default sends nothing. See Language and Thinking Levels.
Config example
Section titled “Config example”{ "provider": "openai", "model": "gpt-5-mini", "approvalModel": "gpt-5-mini"}Failure modes
Section titled “Failure modes”- Missing
CODEN_OPENAI_API_KEY: startup fails (exit code 2). - Invalid model/endpoint: provider errors surface with the
providercategory; failure follows once retry slots are exhausted.
Related references
Section titled “Related references”Anthropic Configuration
Section titled “Anthropic Configuration”Minimal configuration
Section titled “Minimal configuration”export CODEN_ANTHROPIC_API_KEY=sk-ant-...coden --provider anthropic --model claude-sonnet-4-20250514 "your task"Anthropic is not the default provider: pass --provider anthropic explicitly (or set provider: "anthropic"). approvalModel uses the same Anthropic credentials.
Config example
Section titled “Config example”{ "provider": "anthropic", "model": "claude-sonnet-4-20250514", "approvalStrictness": "hard"}Request shape
Section titled “Request shape”- Uses the streaming
messages.streamAPI;max_tokensequalsreservedOutputTokens. - Tools are passed as Anthropic tools (
name/description/input_schema). - The SDK’s internal
maxRetriesis 0: retries are owned by the agent loop. - Thinking blocks (
thinking/redacted_thinkingand signatures) persist asproviderStateand are replayed unchanged after tool calls and resume; mismatched state is ignored when switching providers.
Thinking budgets
Section titled “Thinking budgets”| Level | Behavior |
|---|---|
default |
no thinking parameter sent |
off |
sends { "type": "disabled" } |
minimal |
1024-token budget |
low / medium / high |
25% / 50% / 75% of reservedOutputTokens, clamped to [1024, reservedOutputTokens − 1] |
| any enabled level | requires reservedOutputTokens > 1024, otherwise a configuration error (exit code 2) |
The budget counts inside reservedOutputTokens: a higher level leaves fewer tokens for final text and tool calls in the same response.
Failure modes
Section titled “Failure modes”- Missing
CODEN_ANTHROPIC_API_KEY: startup fails (exit code 2). reservedOutputTokens <= 1024with an enabled thinking level:thinking: ...configuration error.- When a model rejects the requested thinking parameters, the error surfaces as-is with no silent downgrade.
Related references
Section titled “Related references”Custom Base URL
Section titled “Custom Base URL”Configuration
Section titled “Configuration”export CODEN_OPENAI_API_KEY=sk-...export CODEN_OPENAI_BASE_URL=https://api.example.com/v1coden --model your-model-id "your task"CODEN_OPENAI_BASE_URL is consumed directly by the OpenAI SDK and supports proxies, gateways, and any OpenAI-compatible service. It can also live in the config env field (never overwriting shell exports).
Behavior notes
Section titled “Behavior notes”- The base URL affects only the OpenAI provider (the default);
createProviderreads it at construction. - The Anthropic provider always uses the official endpoint; the current version accepts no custom base URL.
- A compatible service must implement the streaming
chat.completionsinterface:stream_options.include_usage, function calling, and streaming tool-call deltas. - CodeN maintains no model capability allowlist:
--thinkingand tool definitions are sent as-is; unsupported services surface provider errors without silent downgrades.
Verify
Section titled “Verify”coden -p "Reply with exactly: coden-ok"The expected output contains coden-ok. If the service is only partially compatible (for example, no usage), stream completion may still succeed.
Common failures
Section titled “Common failures”| Symptom | Cause |
|---|---|
provider.* error |
the endpoint returned non-2xx; check whether the base URL includes /v1 and whether the model ID is valid |
| stream interruption/no output | the service lacks streaming deltas or include_usage |
| parameter rejected | the service does not support fields like reasoning_effort; use --thinking default or a compatible model |
Related references
Section titled “Related references”Language and Thinking Levels
Section titled “Language and Thinking Levels”Language
Section titled “Language”- CodeN defaults to Chinese and never reads the system locale.
- Language resolution:
--lang <zh|en>(this process only, no config write) > user configlanguage> defaultzh. - The project config
languagefield is ignored — language is a user-owned preference. - REPL
/lang <zh|en>switches immediately and atomically updates the user-level config file (preserving other fields, mode0600). - The system prompt, built-in tool descriptions, and UI share one language; the agent may follow a per-task request for another reply language without changing the UI or persisting the preference.
- Third-party plugin names, descriptions, output, and errors always keep the author’s original text.
- Invalid
--langor config values error out (exit code 2); an invalid--langon the command line only reports the error and writes no config.
Thinking levels
Section titled “Thinking levels”Six unified levels: default (default), off, minimal, low, medium, high.
| Entry point | Scope | Persistence |
|---|---|---|
--thinking <level> |
this process | overridden into the session at startup (resume scenarios) |
CODEN_THINKING_LEVEL |
this process | none |
config thinkingLevel |
user/project | the config file itself |
/thinking [level] |
this process and session | written to session records; never to config files |
/new |
— | does not change the level |
Resume precedence: explicit --thinking > saved session value > environment/project/user config > default.
Provider mapping
Section titled “Provider mapping”- OpenAI:
reasoning_effort;off→minimal(displayed asoff→minimal). - Anthropic: explicit thinking budgets (1024 / 25% / 50% / 75%), requiring
reservedOutputTokens > 1024;offsends{ type: "disabled" }. defaultsends no parameter, preserving pre-upgrade behavior.
Scope boundaries
Section titled “Scope boundaries”- Main-agent requests only; context compaction and Smart Approval reviews keep provider defaults.
- The turn-start snapshot covers that turn’s tool loop and retries.
- Explicit settings never silently degrade: unsupported parameters surface as clear provider errors.