Skip to content

providers.json API key from env_var not resolved unless keyring is set #57

Description

@hugosenari

Describe the bug

When defining a custom provider in providers.json with an env_var for the API key, vix fails to resolve the key from that environment variable unless the keyring value is set (with with random stuff).

To reproduce

  1. Create a ~/.vix/providers.json (or ./.vix/providers.json) registering a custom provider with an env_var:
    {
       "credential_methods": [
         {
           "env_var": "GEMINI___API_KEY",
           "keyring": "opencode-api-key", # fails without it but get info from env_var
           "kind": "api_key"
         }
       ],
       "display_name": "Google",
       "id": "google",
       "inference": {
         "auth_header": "x-goog-api-key",
         "auth_scheme": "x-api-key",
         "base_url": "https://generativelanguage.googleapis.com/v1beta/interactions"
       },
       "model_prefix": "google",
       "models": [
         {
           "context_window": 200000,
           "display_name": "Gemini3",
           "spec": "google/gemini-3.5-flash"
         }
       ],
       "wire_format": "chat_completions"
     },
    
  2. Set export MY_CUSTOM_API_KEY=sk-... in your shell — no .env, no keychain entry.
  3. Run vix, select the model myprovider/my-model.
  4. Observe that vix reports no credential for myprovider or fails at request time with an auth error.

Expected behavior

Per the credential resolution order, environment variables should take highest priority and be resolved regardless of whether the OS keychain is available or configured. A custom provider's env_var should work identically to the built-in providers' env vars (e.g. ANTHROPIC_API_KEY, OPENAI_API_KEY).

Actual behavior

The env var is only consulted when the keychain is reachable and/or contains at least one entry for that provider. On systems without a usable keychain (e.g. headless servers, containers, WSL without gnome-keyring), the env var is silently ignored and the credential is reported as missing.

Environment

  • OS: (any headless/container/WSL setup without a functioning keyring daemon)
  • Vix version: (please fill in)
  • Keychain availability: none / unreachable

Additional context

The built-in providers (Anthropic, OpenAI, etc.) resolve their env vars (ANTHROPIC_API_KEY, OPENAI_API_KEY) independently of the keychain, which works fine. The bug seems specific to custom providers defined via providers.json — the credential resolution logic for custom env_var fields may be gated on a prior keychain lookup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions