|
| 1 | +/** |
| 2 | + * API proxy enablement, credentials, and auth customization options. |
| 3 | + */ |
| 4 | + |
| 5 | +export interface ApiProxyCredentialOptions { |
| 6 | + /** |
| 7 | + * Enable API proxy sidecar for holding authentication credentials |
| 8 | + * |
| 9 | + * When true, deploys a Node.js proxy sidecar container that: |
| 10 | + * - Holds OpenAI, Anthropic, GitHub Copilot, and Google Gemini API keys securely |
| 11 | + * - Automatically injects authentication headers |
| 12 | + * - Routes all traffic through Squid to respect domain whitelisting |
| 13 | + * - Proxies requests to LLM providers |
| 14 | + * |
| 15 | + * The sidecar exposes four endpoints accessible from the agent container: |
| 16 | + * - http://api-proxy:10000 - OpenAI API proxy (for Codex) {@link API_PROXY_PORTS.OPENAI} |
| 17 | + * - http://api-proxy:10001 - Anthropic API proxy (for Claude) {@link API_PROXY_PORTS.ANTHROPIC} |
| 18 | + * - http://api-proxy:10002 - GitHub Copilot API proxy {@link API_PROXY_PORTS.COPILOT} |
| 19 | + * - http://api-proxy:10003 - Google Gemini API proxy {@link API_PROXY_PORTS.GEMINI} |
| 20 | + * |
| 21 | + * When the corresponding API key is provided, the following environment |
| 22 | + * variables are set in the agent container: |
| 23 | + * - OPENAI_BASE_URL=http://api-proxy:10000 (set when OPENAI_API_KEY is provided) |
| 24 | + * - ANTHROPIC_BASE_URL=http://api-proxy:10001 (set when ANTHROPIC_API_KEY is provided, or when AWF_AUTH_TYPE=github-oidc and AWF_AUTH_PROVIDER=anthropic) |
| 25 | + * - COPILOT_API_URL=http://api-proxy:10002 (set when COPILOT_GITHUB_TOKEN is provided) |
| 26 | + * - CLAUDE_CODE_API_KEY_HELPER=/usr/local/bin/get-claude-key.sh (set when ANTHROPIC_API_KEY is provided, or when AWF_AUTH_TYPE=github-oidc and AWF_AUTH_PROVIDER=anthropic) |
| 27 | + * |
| 28 | + * API keys are passed via environment variables: |
| 29 | + * - OPENAI_API_KEY - Optional OpenAI API key for Codex |
| 30 | + * - ANTHROPIC_API_KEY - Optional Anthropic API key for Claude |
| 31 | + * - COPILOT_GITHUB_TOKEN - Optional GitHub token for Copilot |
| 32 | + * - COPILOT_PROVIDER_API_KEY - Optional upstream BYOK API key for Copilot-compatible providers |
| 33 | + * - GEMINI_API_KEY - Optional Google Gemini API key |
| 34 | + * |
| 35 | + * @default false |
| 36 | + * @example |
| 37 | + * ```bash |
| 38 | + * # Enable API proxy with keys from environment |
| 39 | + * export OPENAI_API_KEY="sk-..." |
| 40 | + * export ANTHROPIC_API_KEY="sk-ant-..." |
| 41 | + * export COPILOT_GITHUB_TOKEN="ghp_..." |
| 42 | + * awf --enable-api-proxy --allow-domains api.openai.com,api.anthropic.com,api.githubcopilot.com -- command |
| 43 | + * ``` |
| 44 | + * @see API_PROXY_PORTS for port configuration |
| 45 | + */ |
| 46 | + enableApiProxy?: boolean; |
| 47 | + |
| 48 | + /** |
| 49 | + * OpenAI API key for Codex (used by API proxy sidecar) |
| 50 | + * |
| 51 | + * When enableApiProxy is true, this key is injected into the Node.js sidecar |
| 52 | + * container and used to authenticate requests to api.openai.com. |
| 53 | + * |
| 54 | + * The key is NOT exposed to the agent container - only the proxy URL is provided. |
| 55 | + * |
| 56 | + * @default undefined |
| 57 | + */ |
| 58 | + openaiApiKey?: string; |
| 59 | + |
| 60 | + /** |
| 61 | + * Anthropic API key for Claude (used by API proxy sidecar) |
| 62 | + * |
| 63 | + * When enableApiProxy is true, this key is injected into the Node.js sidecar |
| 64 | + * container and used to authenticate requests to api.anthropic.com. |
| 65 | + * |
| 66 | + * The key is NOT exposed to the agent container - only the proxy URL is provided. |
| 67 | + * |
| 68 | + * @default undefined |
| 69 | + */ |
| 70 | + anthropicApiKey?: string; |
| 71 | + |
| 72 | + /** |
| 73 | + * GitHub token for Copilot (used by API proxy sidecar) |
| 74 | + * |
| 75 | + * When enableApiProxy is true, this token is injected into the Node.js sidecar |
| 76 | + * container and used to authenticate requests to api.githubcopilot.com. |
| 77 | + * |
| 78 | + * The token is NOT exposed to the agent container - only the proxy URL is provided. |
| 79 | + * The agent receives a placeholder value that is protected by the one-shot-token library. |
| 80 | + * |
| 81 | + * @default undefined |
| 82 | + */ |
| 83 | + copilotGithubToken?: string; |
| 84 | + |
| 85 | + /** |
| 86 | + * Upstream BYOK API key for Copilot-compatible providers (used by API proxy sidecar) |
| 87 | + * |
| 88 | + * When enableApiProxy is true and this key is provided, AWF routes Copilot CLI |
| 89 | + * through the sidecar in direct-BYOK mode (Azure Foundry, OpenRouter, etc.). |
| 90 | + * The real key is injected into the Node.js sidecar container and used to |
| 91 | + * authenticate requests to the user-supplied COPILOT_PROVIDER_BASE_URL. |
| 92 | + * |
| 93 | + * The key is NOT exposed to the agent container - only the proxy URL is provided. |
| 94 | + * The agent receives a placeholder value so Copilot CLI's startup auth check passes. |
| 95 | + * |
| 96 | + * Sourced from `process.env.COPILOT_PROVIDER_API_KEY` in build-config; matches the |
| 97 | + * pattern used by OPENAI_API_KEY, ANTHROPIC_API_KEY, COPILOT_GITHUB_TOKEN, and |
| 98 | + * GEMINI_API_KEY. |
| 99 | + * |
| 100 | + * @default undefined |
| 101 | + */ |
| 102 | + copilotProviderApiKey?: string; |
| 103 | + |
| 104 | + /** |
| 105 | + * Google Gemini API key (used by API proxy sidecar) |
| 106 | + * |
| 107 | + * When enableApiProxy is true, this key is injected into the Node.js sidecar |
| 108 | + * container and used to authenticate requests to generativelanguage.googleapis.com. |
| 109 | + * |
| 110 | + * The key is NOT exposed to the agent container - only the proxy URL is provided. |
| 111 | + * The agent receives a placeholder value so Gemini CLI's startup auth check passes. |
| 112 | + * |
| 113 | + * @default undefined |
| 114 | + */ |
| 115 | + geminiApiKey?: string; |
| 116 | + |
| 117 | + /** |
| 118 | + * Custom auth header name for OpenAI API requests (used by API proxy sidecar) |
| 119 | + * |
| 120 | + * When set, the proxy uses this header name instead of the default |
| 121 | + * standard Authorization bearer-header format. The key is sent as the raw header |
| 122 | + * value without a "Bearer" prefix. |
| 123 | + * |
| 124 | + * Useful for internal AI gateways (e.g. Azure OpenAI) that require a |
| 125 | + * different header name such as `api-key`. |
| 126 | + * |
| 127 | + * Can be set via: |
| 128 | + * - CLI flag: `--openai-api-auth-header <name>` |
| 129 | + * - Environment variable: `AWF_OPENAI_AUTH_HEADER` |
| 130 | + * |
| 131 | + * @default undefined (uses a standard Authorization bearer header) |
| 132 | + * @example 'api-key' |
| 133 | + */ |
| 134 | + openaiApiAuthHeader?: string; |
| 135 | + |
| 136 | + /** |
| 137 | + * Custom auth header name for Anthropic API requests (used by API proxy sidecar) |
| 138 | + * |
| 139 | + * When set, the proxy uses this header name instead of the default `x-api-key`. |
| 140 | + * |
| 141 | + * Useful for internal AI gateways that require a different header name. |
| 142 | + * |
| 143 | + * Can be set via: |
| 144 | + * - CLI flag: `--anthropic-api-auth-header <name>` |
| 145 | + * - Environment variable: `AWF_ANTHROPIC_AUTH_HEADER` |
| 146 | + * |
| 147 | + * @default 'x-api-key' |
| 148 | + * @example 'api-key' |
| 149 | + */ |
| 150 | + anthropicApiAuthHeader?: string; |
| 151 | + |
| 152 | + /** |
| 153 | + * Anthropic OIDC token exchange endpoint override. |
| 154 | + * |
| 155 | + * When set, AWF passes this value to the API proxy as |
| 156 | + * `AWF_AUTH_ANTHROPIC_TOKEN_URL` for Anthropic WIF/OIDC exchange. |
| 157 | + * |
| 158 | + * Intended for non-sensitive endpoint customization and typically set via |
| 159 | + * config file (`apiProxy.auth.anthropicTokenUrl`). |
| 160 | + * |
| 161 | + * @default 'https://api.anthropic.com/v1/oauth/token' |
| 162 | + */ |
| 163 | + anthropicTokenUrl?: string; |
| 164 | +} |
0 commit comments