Skip to content

[Bug]: Model-level test connection fails with 'API key required' when only server-side key is configured #308

@cosarah

Description

@cosarah

Bug Description

In the Settings panel, when testing connectivity for a language model provider, the provider-level "Test Connection" button works correctly — it sends the request to the server, which can use server-side configured API keys (e.g. via environment variables). However, the model-level "Test Connection" button (inside the model edit dialog) has a client-side guard that immediately rejects the request if the client-side API key field is empty, even when the server has a valid API key configured.

Root cause: In components/settings/model-edit-dialog.tsx line 62, handleTestModel checks if (!editingModel || !apiKey) and short-circuits with an "API Key is required" error before ever sending the request to /api/verify-model. The provider-level test in components/settings/provider-config-panel.tsx does not have this guard and correctly delegates the check to the server.

Steps to Reproduce

  1. Configure an API key for a provider only on the server side (e.g., set OPENAI_API_KEY in .env.local or server environment variables)
  2. Do not enter an API key in the client-side Settings panel for that provider
  3. Open Settings → select the provider → click "Test Connection" → ✅ Success
  4. Click on a specific model under that provider to open the model edit dialog
  5. Click "Test Connection" in the model edit dialog → ❌ Shows "API Key is required"

Expected Behavior

The model-level "Test Connection" should behave consistently with the provider-level test: send the request to the server and let the server-side API route handle API key resolution (falling back to server-configured keys when client-side key is empty).

Actual Behavior

The model-level test connection immediately shows "API Key is required" error without sending any request to the server, even though the server has a valid API key configured and the provider-level test works fine.

Deployment Method

Local development (pnpm dev)

Additional Context

The fix should remove or adjust the !apiKey guard in model-edit-dialog.tsx handleTestModel to match the provider-level behavior — letting the server handle API key validation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions