@@ -16,6 +16,7 @@ import { server } from "./server"
1616
1717interface RunServerOptions {
1818 port: number
19+ host ? : string
1920 verbose: boolean
2021 accountType: string
2122 manual: boolean
@@ -25,13 +26,22 @@ interface RunServerOptions {
2526 claudeCode: boolean
2627 showToken: boolean
2728 proxyEnv: boolean
29+ apiKeys ?: Array < string >
2830}
2931
3032export async function runServer ( options : RunServerOptions ) : Promise < void > {
3133 if ( options . proxyEnv ) {
3234 initProxyFromEnv ( )
3335 }
3436
37+ // PR #144: Configure API keys (@ZiuChen)
38+ if ( options . apiKeys && options . apiKeys . length > 0 ) {
39+ state . apiKeys = options . apiKeys
40+ consola . info (
41+ `API key authentication enabled with ${ options . apiKeys . length } key(s)` ,
42+ )
43+ }
44+
3545 if ( options . verbose ) {
3646 consola . level = 5
3747 consola . info ( "Verbose logging enabled" )
@@ -64,7 +74,9 @@ export async function runServer(options: RunServerOptions): Promise<void> {
6474 `Available models: \n${ state . models ?. data . map ( ( model ) => `- ${ model . id } ` ) . join ( "\n" ) } ` ,
6575 )
6676
67- const serverUrl = `http://localhost:${ options . port } `
77+ // PR #157: Build server URL with host option (@berilevi)
78+ const host = options . host ?? "localhost"
79+ const serverUrl = `http://${ host } :${ options . port } `
6880
6981 if ( options . claudeCode ) {
7082 invariant ( state . models , "Models should be loaded by now" )
@@ -117,6 +129,7 @@ export async function runServer(options: RunServerOptions): Promise<void> {
117129 serve ( {
118130 fetch : server . fetch as ServerHandler ,
119131 port : options . port ,
132+ hostname : options . host ,
120133 } )
121134}
122135
@@ -132,6 +145,13 @@ export const start = defineCommand({
132145 default : "4141" ,
133146 description : "Port to listen on" ,
134147 } ,
148+ // PR #157: Add --host option (@berilevi)
149+ host : {
150+ alias : "H" ,
151+ type : "string" ,
152+ description :
153+ "Host/interface to bind to (e.g., 127.0.0.1 for localhost only)" ,
154+ } ,
135155 verbose : {
136156 alias : "v" ,
137157 type : "boolean" ,
@@ -184,15 +204,30 @@ export const start = defineCommand({
184204 default : false ,
185205 description : "Initialize proxy from environment variables" ,
186206 } ,
207+ // PR #144: Support specifying multiple API keys (@ZiuChen)
208+ "api-key" : {
209+ alias : "k" ,
210+ type : "string" ,
211+ description :
212+ "API key(s) for authentication. Can be specified multiple times for multiple keys" ,
213+ } ,
187214 } ,
188215 run ( { args } ) {
189216 const rateLimitRaw = args [ "rate-limit" ]
190217 const rateLimit =
191218 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
192219 rateLimitRaw === undefined ? undefined : Number . parseInt ( rateLimitRaw , 10 )
193220
221+ // Parse API keys (can be a single string or array)
222+ const apiKeyArg = args [ "api-key" ]
223+ let apiKeys : Array < string > | undefined
224+ if ( apiKeyArg ) {
225+ apiKeys = Array . isArray ( apiKeyArg ) ? apiKeyArg : [ apiKeyArg ]
226+ }
227+
194228 return runServer ( {
195229 port : Number . parseInt ( args . port , 10 ) ,
230+ host : args . host ,
196231 verbose : args . verbose ,
197232 accountType : args [ "account-type" ] ,
198233 manual : args . manual ,
@@ -202,6 +237,7 @@ export const start = defineCommand({
202237 claudeCode : args [ "claude-code" ] ,
203238 showToken : args [ "show-token" ] ,
204239 proxyEnv : args [ "proxy-env" ] ,
240+ apiKeys,
205241 } )
206242 } ,
207243} )
0 commit comments