nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] A hosted provider without an API key is accepted because a dummy key is always filled in

Open addyCooks opened this issue 1 week ago • 1 comments

Description

validateProviderCredentials is meant to throw "API key required for hosted providers", but the provider loader always sets apiKey: provider.apiKey || 'dummy-key'. The check sees a truthy key and never fails, so the user only learns about the missing key from a 401 on the first request.

Environment

  • OS: Windows 11 Home 10.0.26300
  • Node version: v22.22.3
  • Nanocoder version: 1.32.0 (built from main at eb7dee57)
  • Provider: Any hosted OpenAI-compatible provider
  • Model: Not model-specific

Steps to Reproduce

  1. In a project folder create agents.config.json: {"nanocoder":{"providers":[{"name":"hosted","baseUrl":"https://api.example.com/v1","models":["m"]}]}}
  2. Run createLLMClient('hosted').

Expected Behavior

It throws API key required for hosted providers.

Actual Behavior

A client is created.

Logs/Screenshots

RESULT:created a client for a hosted provider that has no API key

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder (main)

Suggested fix:

  • source/client-factory.ts:265: only fall back to 'dummy-key' when the base URL is a local server (use the existing isLocalURL), so validateProviderCredentials (:289-316) can see a missing key.
  • Check that local providers (Ollama, LM Studio) still start without a key.
  • Add a test for a hosted provider with no key and for a local one.

addyCooks avatar Nov 23 '26 07:11 addyCooks

Picked this up, fix is in #2364.

harpreetkbadhan avatar Nov 23 '26 09:11 harpreetkbadhan