feat(setup): separate env namespace for custom OpenAI-compat provider#3248
Open
TheArchitectit wants to merge 3 commits into
Open
feat(setup): separate env namespace for custom OpenAI-compat provider#3248TheArchitectit wants to merge 3 commits into
TheArchitectit wants to merge 3 commits into
Conversation
The /setup wizard saves apiKey and baseUrl to ~/.claw/settings.json, but the API client constructors (OpenAiCompatClient::from_env, AnthropicClient::from_env) only read environment variables. This caused saved provider settings to be silently ignored — you'd run /setup, set a custom URL and API key, and the runtime would still try to use the default endpoint. Now AnthropicRuntimeClient::new() calls inject_config_as_env_fallbacks() before constructing the API client. This function loads the config file's provider settings and sets the corresponding env vars (OPENAI_API_KEY, OPENAI_BASE_URL, etc.) only when they aren't already set — preserving the 3-tier resolution order: env var > .env file > stored config. This is a process-level env injection (set_var), so it only affects the current claw process and its children, not the parent shell.
…oints - Move config-to-env injection out of AnthropicRuntimeClient::new so parallel unit tests are not affected by global env mutations. - Call inject_config_as_env_fallbacks() once at binary startup in run(), preserving the env-var > .env > stored-config precedence. - Normalize bare model names (e.g. openclaw) to openai/openclaw when a custom OpenAI-compatible base URL is configured, so validation passes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The Custom (OpenAI-compat) /setup option was saving kind: openai and injecting OPENAI_API_KEY / OPENAI_BASE_URL. That collides with users who have real OpenAI/NeuralWatt credentials in their environment. Introduce a dedicated custom-openai provider kind that uses its own environment variables: - CLAWCUSTOMOPENAI_API_KEY - CLAWCUSTOMOPENAI_BASE_URL A new custom/ routing prefix selects the OpenAI-compatible client with those env vars and is stripped on the wire, so the proxy receives the bare model id. /setup now saves kind: custom-openai and prompts for the new env vars. Bare model names saved by /setup are normalized to custom/<model>. Manual verification against http://100.96.49.42:4001/v1 succeeds. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
/setupwizard's "Custom (OpenAI-compat)" option savedkind: "openai"and injectedOPENAI_API_KEY/OPENAI_BASE_URL. That collides with users who already have real OpenAI, NeuralWatt, or other platform credentials in their environment, so the saved custom proxy URL was ignored and requests were misrouted.Changes
New provider kind:
custom-openaiCLAWCUSTOMOPENAI_API_KEYCLAWCUSTOMOPENAI_BASE_URLcustom/selects the OpenAI-compatible client with those env vars and is stripped on the wire, so the proxy receives the bare model id./setupwizard updatedkind: "custom-openai".CLAWCUSTOMOPENAI_API_KEY/CLAWCUSTOMOPENAI_BASE_URL./setupare normalized tocustom/<model>.Saved settings are applied at startup
inject_config_as_env_fallbacks()is called once inrun()before any runtime threads are spawned..envfile > stored config.API routing
metadata_for_modelanddetect_provider_kindrecognizecustom/.OpenAiCompatConfig::custom_openai()reads the new env vars.wire_model_for_base_urlstripscustom/prefix.Tests
custom/prefix routes toCLAWCUSTOMOPENAI_*env vars.custom/is stripped on the wire.inject_config_as_env_fallbackssets both standard and custom env vars.custom/.Docs
USAGE.mdprovider matrix and prefix-routing section./setupwizard section explaining the custom provider.Verification
cargo test -p apipasses.cargo test -p rusty-claude-cli --bin claw config_modelpasses.cargo test -p rusty-claude-cli --bin claw inject_configpasses.http://100.96.49.42:4001/v1with modelopenclaw_3750succeeded.Notes
upstream/mainwhere the TUI changes are not present.kind: "openai"with a custom base URL can re-run/setupto migrate to the new namespace.🤖 Generated with Claude Code
Co-Authored-By: Claude Fable 5 noreply@anthropic.com