Skip to content

Conversation

@lars-osterberg
Copy link

@lars-osterberg lars-osterberg commented Jan 13, 2026

Summary

Add support for fetching API keys dynamically by executing a command. This enables integration with credential managers, token services, or any external authentication system.

Related Issues

This PR addresses several feature requests from the community:

Motivation

Currently, API keys can be provided via:

  • Static values in the config file
  • Environment variables using {env:VAR_NAME} syntax
  • The /connect command (stored in auth.json)

This works well for simple setups, but doesn't support:

  • Credential helpers that fetch tokens dynamically (similar to git's credential.helper)
  • Token services like LiteLLM proxy servers that require short-lived tokens
  • Secret managers (1Password CLI, AWS Secrets Manager, HashiCorp Vault, etc.)
  • Desktop apps that can't inherit environment variables from shell wrappers

Usage

{
  "provider": {
    "my-provider": {
      "options": {
        "apiKeyCommand": ["my-credential-helper", "get-token"]
      }
    }
  }
}

The command should output the API key to stdout. The output is trimmed of whitespace.

Examples

// 1Password CLI
{
  "provider": {
    "openai": {
      "options": {
        "apiKeyCommand": ["op", "read", "op://Private/OpenAI/api-key"]
      }
    }
  }
}

// Custom token service (e.g., LiteLLM with IDP auth)
{
  "provider": {
    "my-llm-proxy": {
      "options": {
        "apiKeyCommand": ["my-auth-cli", "get-token"]
      }
    }
  }
}

// AWS Secrets Manager
{
  "provider": {
    "openai": {
      "options": {
        "apiKeyCommand": ["aws", "secretsmanager", "get-secret-value", "--secret-id", "openai-key", "--query", "SecretString", "--output", "text"]
      }
    }
  }
}

Design Notes

This complements the existing {env:VAR_NAME} syntax rather than replacing it. The apiKeyCommand approach is:

  • Explicit: Only used for API keys, not arbitrary config values
  • Secure: Command is executed at SDK initialization time, not config parse time
  • Flexible: Supports any command that outputs a token to stdout

An alternative approach would be adding {exec:command} syntax similar to {env:...}, but apiKeyCommand is more targeted and follows patterns used by:

  • AWS CLI: credential_process in ~/.aws/config
  • Git: credential.helper configuration
  • Docker: credHelpers in ~/.docker/config.json

Changes

  • Added apiKeyCommand field to provider options in config schema
  • Added resolveApiKeyCommand() helper function to execute the command
  • Updated getSDK() to check for apiKeyCommand when no apiKey is set

Add support for fetching API keys dynamically by executing a command.
This is useful for integrating with credential managers, token services,
or any external authentication system.

Example configuration:
{
  "provider": {
    "my-provider": {
      "options": {
        "apiKeyCommand": ["my-credential-helper", "get-token"]
      }
    }
  }
}

The command should output the API key to stdout. This is similar to
patterns used by AWS CLI (credential_process) and git (credential.helper).
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant