Skip to content

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.

终端窗口
export CODEN_OPENAI_API_KEY=sk-...
coden

openai is the default provider with model gpt-5-mini. Overrides:

终端窗口
export CODEN_MODEL=gpt-5-mini
coden --model gpt-5-mini "your task"
终端窗口
export CODEN_OPENAI_API_KEY=sk-...
export CODEN_OPENAI_BASE_URL=https://api.example.com/v1
coden --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.

  • Uses the streaming chat.completions API with stream_options.include_usage for usage.
  • Tools are passed as OpenAI function calling (type: "function", name/description/JSON Schema).
  • max_completion_tokens of every request equals reservedOutputTokens (default 8192).
  • The SDK’s internal maxRetries is 0: retries are owned by the agent loop (up to 3 exponential backoffs; see Agent Loop).

--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.

{
"provider": "openai",
"model": "gpt-5-mini",
"approvalModel": "gpt-5-mini"
}
  • Missing CODEN_OPENAI_API_KEY: startup fails (exit code 2).
  • Invalid model/endpoint: provider errors surface with the provider category; failure follows once retry slots are exhausted.
终端窗口
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.

{
"provider": "anthropic",
"model": "claude-sonnet-4-20250514",
"approvalStrictness": "hard"
}
  • Uses the streaming messages.stream API; max_tokens equals reservedOutputTokens.
  • Tools are passed as Anthropic tools (name/description/input_schema).
  • The SDK’s internal maxRetries is 0: retries are owned by the agent loop.
  • Thinking blocks (thinking/redacted_thinking and signatures) persist as providerState and are replayed unchanged after tool calls and resume; mismatched state is ignored when switching providers.
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.

  • Missing CODEN_ANTHROPIC_API_KEY: startup fails (exit code 2).
  • reservedOutputTokens <= 1024 with an enabled thinking level: thinking: ... configuration error.
  • When a model rejects the requested thinking parameters, the error surfaces as-is with no silent downgrade.
终端窗口
export CODEN_OPENAI_API_KEY=sk-...
export CODEN_OPENAI_BASE_URL=https://api.example.com/v1
coden --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).

  • The base URL affects only the OpenAI provider (the default); createProvider reads 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.completions interface: stream_options.include_usage, function calling, and streaming tool-call deltas.
  • CodeN maintains no model capability allowlist: --thinking and tool definitions are sent as-is; unsupported services surface provider errors without silent downgrades.
终端窗口
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.

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
  • CodeN defaults to Chinese and never reads the system locale.
  • Language resolution: --lang <zh|en> (this process only, no config write) > user config language > default zh.
  • The project config language field 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, mode 0600).
  • 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 --lang or config values error out (exit code 2); an invalid --lang on the command line only reports the error and writes no config.

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.

  • OpenAI: reasoning_effort; off→minimal (displayed as off→minimal).
  • Anthropic: explicit thinking budgets (1024 / 25% / 50% / 75%), requiring reservedOutputTokens > 1024; off sends { type: "disabled" }.
  • default sends no parameter, preserving pre-upgrade behavior.
  • 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.