@@ -25,8 +25,30 @@ interface RunServerOptions {
2525 claudeCode: boolean
2626 showToken: boolean
2727 proxyEnv: boolean
28+ apiKeys ?: Array < string >
2829}
2930
31+ /**
32+ * Start and configure the Copilot API server according to the provided options.
33+ *
34+ * Configures proxy and logging, initializes global state and credentials, ensures
35+ * required paths and model data are cached, optionally generates a Claude Code
36+ * launch command (and attempts to copy it to the clipboard), prints a usage
37+ * viewer URL, and begins serving HTTP requests on the specified port.
38+ *
39+ * @param options - Server startup options:
40+ * - port: Port number to listen on
41+ * - verbose: Enable verbose logging
42+ * - accountType: Account plan to use ("individual", "business", "enterprise")
43+ * - manual: Require manual approval for requests
44+ * - rateLimit: Seconds to wait between requests (optional)
45+ * - rateLimitWait: Wait instead of erroring when rate limit is hit
46+ * - githubToken: GitHub token to use (optional; if omitted a token setup prompt may run)
47+ * - claudeCode: Generate a Claude Code environment launch command
48+ * - showToken: Expose GitHub/Copilot tokens in responses for debugging
49+ * - proxyEnv: Initialize proxy settings from environment variables
50+ * - apiKeys: Optional list of API keys to enable API key authentication
51+ */
3052export async function runServer ( options : RunServerOptions ) : Promise < void > {
3153 if ( options . proxyEnv ) {
3254 initProxyFromEnv ( )
@@ -46,6 +68,13 @@ export async function runServer(options: RunServerOptions): Promise<void> {
4668 state . rateLimitSeconds = options . rateLimit
4769 state . rateLimitWait = options . rateLimitWait
4870 state . showToken = options . showToken
71+ state . apiKeys = options . apiKeys
72+
73+ if ( state . apiKeys && state . apiKeys . length > 0 ) {
74+ consola . info (
75+ `API key authentication enabled with ${ state . apiKeys . length } key(s)` ,
76+ )
77+ }
4978
5079 await ensurePaths ( )
5180 await cacheVSCodeVersion ( )
@@ -184,13 +213,24 @@ export const start = defineCommand({
184213 default : false ,
185214 description : "Initialize proxy from environment variables" ,
186215 } ,
216+ "api-key" : {
217+ type : "string" ,
218+ description : "API keys for authentication" ,
219+ } ,
187220 } ,
188221 run ( { args } ) {
189222 const rateLimitRaw = args [ "rate-limit" ]
190223 const rateLimit =
191224 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
192225 rateLimitRaw === undefined ? undefined : Number . parseInt ( rateLimitRaw , 10 )
193226
227+ // Handle multiple API keys - citty may pass a string or array
228+ const apiKeyRaw = args [ "api-key" ]
229+ let apiKeys : Array < string > | undefined
230+ if ( apiKeyRaw ) {
231+ apiKeys = Array . isArray ( apiKeyRaw ) ? apiKeyRaw : [ apiKeyRaw ]
232+ }
233+
194234 return runServer ( {
195235 port : Number . parseInt ( args . port , 10 ) ,
196236 verbose : args . verbose ,
@@ -202,6 +242,7 @@ export const start = defineCommand({
202242 claudeCode : args [ "claude-code" ] ,
203243 showToken : args [ "show-token" ] ,
204244 proxyEnv : args [ "proxy-env" ] ,
245+ apiKeys,
205246 } )
206247 } ,
207- } )
248+ } )
0 commit comments