()
| 119 | * Get API key or exit with setup instructions. |
| 120 | */ |
| 121 | export function requireApiKey(): string { |
| 122 | const resolution = resolveApiKeyInfo(); |
| 123 | if (!resolution) { |
| 124 | console.error("No OpenAI API key found."); |
| 125 | console.error(""); |
| 126 | console.error("Run: $D setup"); |
| 127 | console.error(" or save to ~/.gstack/openai.json: { \"api_key\": \"sk-...\" }"); |
| 128 | console.error(" or set OPENAI_API_KEY environment variable"); |
| 129 | console.error(""); |
| 130 | console.error("Get a key at: https://platform.openai.com/api-keys"); |
| 131 | process.exit(1); |
| 132 | } |
| 133 | console.error(`Using OpenAI key from ${describeApiKeySource(resolution)}.`); |
| 134 | if (resolution.warning) console.error(resolution.warning); |
| 135 | return resolution.key; |
| 136 | } |
no test coverage detected