Skip to content

Provider and Model

A provider is the model-protocol adapter, not the agent itself. CodeN currently implements OpenAI and Anthropic providers. You choose the model ID; CodeN maintains no capability allowlist and does not silently pretend success when a service rejects a parameter.

CodeN supports exactly two providers: openai (default) and anthropic. The provider determines the API endpoint, authentication, and thinking-parameter mapping; the default model is gpt-5-mini.

终端窗口
export CODEN_OPENAI_API_KEY=sk-...
coden "say hello"

Custom compatible endpoint (proxy or compatible service):

终端窗口
export CODEN_OPENAI_API_KEY=sk-...
export CODEN_OPENAI_BASE_URL=https://api.example.com/v1
coden --model your-model-id "say hello"
终端窗口
export CODEN_ANTHROPIC_API_KEY=sk-ant-...
coden --provider anthropic --model claude-sonnet-4-20250514 "say hello"

Switching providers requires an explicit --provider anthropic. The provider accepts only openai or anthropic; any other value fails argument parsing.

CodeN reads process environment variables when constructing the provider. Sources, highest first:

  1. Environment variables already exported in the shell before starting CodeN.
  2. The config env field: injected into the process environment at config load time, but it does not overwrite an already-exported shell variable of the same name.
  3. With no key set, startup fails with exit code 2 and an error shaped like CODEN_OPENAI_API_KEY is required.

Config env example (user scope, ~/.config/coden/config.json):

{
"env": {
"CODEN_OPENAI_API_KEY": "sk-..."
}
}

A project-level <workspace>/.coden/config.json accepts the same env field; when both scopes are merged, project-level keys override user-level keys one by one.

  • Never put a key in a directory that gets committed, shared, or distributed. Supported locations are ~/.config/coden/, .coden/ (excluded by .gitignore), and the config env field.
  • CodeN does not read .env files automatically; set dotenv-load in just affects only just subprocesses during development.
  • Session JSONL and trace files may contain model reasoning and user input; do not share them without review.
终端窗口
coden -p "Reply with exactly: coden-ok"

Print mode emits plain text and exits after a single turn, which makes it a good authentication and endpoint check. The expected output contains coden-ok.

终端窗口
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.