pi-mono icon indicating copy to clipboard operation
pi-mono copied to clipboard

Support shell command execution for API key resolution in models.json

Open cv opened this issue 2 months ago • 2 comments

Add ! prefix support to apiKey field in models.json to execute shell commands and use stdout as the API key. This allows users to store API keys in secure credential managers like macOS Keychain, 1Password, Bitwarden, or HashiCorp Vault.

Example

{
  "providers": {
    "my-provider": {
      "baseUrl": "https://api.example.com",
      "apiKey": "!security find-generic-password -ws 'anthropic'",
      "api": "anthropic-messages",
      "models": [...]
    }
  }
}

API Key Resolution

The apiKey field now supports three formats:

  • "!command" - Executes the command and uses stdout (trimmed)
  • Environment variable name (e.g., "MY_API_KEY") - Uses the value of the environment variable
  • Literal value - Used directly as the API key

Changes

  • packages/coding-agent/src/core/model-registry.ts: Added command execution support to resolveApiKeyConfig()
  • packages/coding-agent/test/model-registry.test.ts: Added 9 tests for API key resolution
  • packages/coding-agent/README.md: Updated documentation
  • packages/coding-agent/CHANGELOG.md: Added changelog entry

Fixes #697

cv avatar Jan 16 '26 01:01 cv