Issue Summary
When using the openai-like provider, the NPCSH_API_URL environment variable is not respected for setting the API base URL. Users are forced to specify api_url in each NPC configuration instead of being able to set it globally via environment variable.
Problem Location
File: npcsh/_state.py
Function: setup_shell()
Lines: ~4145-4155
Current Behavior
During team initialization in setup_shell(), NPCs are assigned default model and provider values from the environment:
for npc_name, npc_obj in team.npcs.items():
if not npc_obj.model:
npc_obj.model = initial_state.chat_model
if not npc_obj.provider:
npc_obj.provider = initial_state.chat_provider
However, there's no corresponding check to inject NPCSH_API_URL for NPCs using the openai-like provider that don't have an explicit api_url set.
Expected Behavior
Similar to how default model and provider are injected during initialization, NPCs using openai-like provider without an explicit api_url should receive the value from NPCSH_API_URL environment variable.
Use Case
Users trying to use Ollama Cloud services (or other OpenAI-compatible APIs) with the openai-like provider cannot set the API URL globally via NPCSH_API_URL. They are forced to specify api_url in each NPC configuration, which is inconvenient and inconsistent with how other configuration values are handled.
Proposed Fix
In npcsh/_state.py, during the setup_shell() function where default model and provider are set, add logic to inject NPCSH_API_URL for openai-like provider NPCs:
for npc_name, npc_obj in team.npcs.items():
if not npc_obj.model:
npc_obj.model = initial_state.chat_model
if not npc_obj.provider:
npc_obj.provider = initial_state.chat_provider
# Inject NPCSH_API_URL for openai-like provider if not explicitly set
if not getattr(npc_obj, 'api_url', None) and npc_obj.provider == 'openai-like':
npc_obj.api_url = os.environ.get("NPCSH_API_URL")
Apply the same logic to forenpc if present.
Why npcsh Layer
The fix belongs in npcsh during team initialization, where npcsh-specific environment variables should be injected into NPC configurations. This keeps the core npcpy library agnostic while allowing npcsh to provide configuration defaults at the appropriate layer.
Testing
Test scenarios:
- Set
NPCSH_API_URL=https://ollama-cloud.example.com/v1 and use provider: openai-like without explicit api_url - should use the env var
- Explicit
api_url parameter in NPC config should still take precedence over environment variable
- Verify existing behavior for other providers is not affected
Issue Summary
When using the
openai-likeprovider, theNPCSH_API_URLenvironment variable is not respected for setting the API base URL. Users are forced to specifyapi_urlin each NPC configuration instead of being able to set it globally via environment variable.Problem Location
File:
npcsh/_state.pyFunction:
setup_shell()Lines: ~4145-4155
Current Behavior
During team initialization in
setup_shell(), NPCs are assigned default model and provider values from the environment:However, there's no corresponding check to inject
NPCSH_API_URLfor NPCs using theopenai-likeprovider that don't have an explicitapi_urlset.Expected Behavior
Similar to how default model and provider are injected during initialization, NPCs using
openai-likeprovider without an explicitapi_urlshould receive the value fromNPCSH_API_URLenvironment variable.Use Case
Users trying to use Ollama Cloud services (or other OpenAI-compatible APIs) with the
openai-likeprovider cannot set the API URL globally viaNPCSH_API_URL. They are forced to specifyapi_urlin each NPC configuration, which is inconvenient and inconsistent with how other configuration values are handled.Proposed Fix
In
npcsh/_state.py, during thesetup_shell()function where default model and provider are set, add logic to injectNPCSH_API_URLforopenai-likeprovider NPCs:Apply the same logic to
forenpcif present.Why npcsh Layer
The fix belongs in
npcshduring team initialization, wherenpcsh-specific environment variables should be injected into NPC configurations. This keeps the corenpcpylibrary agnostic while allowingnpcshto provide configuration defaults at the appropriate layer.Testing
Test scenarios:
NPCSH_API_URL=https://ollama-cloud.example.com/v1and useprovider: openai-likewithout explicitapi_url- should use the env varapi_urlparameter in NPC config should still take precedence over environment variable