@@ -49,6 +49,11 @@ pub struct ModelProviderInfo {
4949 /// Environment variable that stores the user's API key for this provider.
5050 pub env_key : Option < String > ,
5151
52+ /// The value of the key to use with the provider. Use of this config is
53+ /// discouraged in favor of `env_key` for security reasons, but this may
54+ /// be necessary when using this programmatically.
55+ pub secret_key : Option < String > ,
56+
5257 /// Optional instructions to help the user get a valid value for the
5358 /// variable and set it.
5459 pub env_key_instructions : Option < String > ,
@@ -102,14 +107,18 @@ impl ModelProviderInfo {
102107 client : & ' a reqwest:: Client ,
103108 auth : & Option < CodexAuth > ,
104109 ) -> crate :: error:: Result < reqwest:: RequestBuilder > {
105- let effective_auth = match self . api_key ( ) {
106- Ok ( Some ( key) ) => Some ( CodexAuth :: from_api_key ( & key) ) ,
107- Ok ( None ) => auth. clone ( ) ,
108- Err ( err) => {
109- if auth. is_some ( ) {
110- auth. clone ( )
111- } else {
112- return Err ( err) ;
110+ let effective_auth = if let Some ( secret_key) = & self . secret_key {
111+ Some ( CodexAuth :: from_api_key ( secret_key) )
112+ } else {
113+ match self . api_key ( ) {
114+ Ok ( Some ( key) ) => Some ( CodexAuth :: from_api_key ( & key) ) ,
115+ Ok ( None ) => auth. clone ( ) ,
116+ Err ( err) => {
117+ if auth. is_some ( ) {
118+ auth. clone ( )
119+ } else {
120+ return Err ( err) ;
121+ }
113122 }
114123 }
115124 } ;
@@ -274,6 +283,7 @@ pub fn built_in_model_providers() -> HashMap<String, ModelProviderInfo> {
274283 . filter ( |v| !v. trim ( ) . is_empty ( ) ) ,
275284 env_key : None ,
276285 env_key_instructions : None ,
286+ secret_key : None ,
277287 wire_api : WireApi :: Responses ,
278288 query_params : None ,
279289 http_headers : Some (
@@ -333,6 +343,7 @@ pub fn create_oss_provider_with_base_url(base_url: &str) -> ModelProviderInfo {
333343 base_url : Some ( base_url. into ( ) ) ,
334344 env_key : None ,
335345 env_key_instructions : None ,
346+ secret_key : None ,
336347 wire_api : WireApi :: Chat ,
337348 query_params : None ,
338349 http_headers : None ,
@@ -372,6 +383,7 @@ base_url = "http://localhost:11434/v1"
372383 base_url : Some ( "http://localhost:11434/v1" . into ( ) ) ,
373384 env_key : None ,
374385 env_key_instructions : None ,
386+ secret_key : None ,
375387 wire_api : WireApi :: Chat ,
376388 query_params : None ,
377389 http_headers : None ,
@@ -399,6 +411,7 @@ query_params = { api-version = "2025-04-01-preview" }
399411 base_url : Some ( "https://xxxxx.openai.azure.com/openai" . into ( ) ) ,
400412 env_key : Some ( "AZURE_OPENAI_API_KEY" . into ( ) ) ,
401413 env_key_instructions : None ,
414+ secret_key : None ,
402415 wire_api : WireApi :: Chat ,
403416 query_params : Some ( maplit:: hashmap! {
404417 "api-version" . to_string( ) => "2025-04-01-preview" . to_string( ) ,
@@ -429,6 +442,7 @@ env_http_headers = { "X-Example-Env-Header" = "EXAMPLE_ENV_VAR" }
429442 base_url : Some ( "https://example.com" . into ( ) ) ,
430443 env_key : Some ( "API_KEY" . into ( ) ) ,
431444 env_key_instructions : None ,
445+ secret_key : None ,
432446 wire_api : WireApi :: Chat ,
433447 query_params : None ,
434448 http_headers : Some ( maplit:: hashmap! {
@@ -455,6 +469,7 @@ env_http_headers = { "X-Example-Env-Header" = "EXAMPLE_ENV_VAR" }
455469 base_url : Some ( base_url. into ( ) ) ,
456470 env_key : None ,
457471 env_key_instructions : None ,
472+ secret_key : None ,
458473 wire_api : WireApi :: Responses ,
459474 query_params : None ,
460475 http_headers : None ,
@@ -487,6 +502,7 @@ env_http_headers = { "X-Example-Env-Header" = "EXAMPLE_ENV_VAR" }
487502 base_url : Some ( "https://example.com" . into ( ) ) ,
488503 env_key : None ,
489504 env_key_instructions : None ,
505+ secret_key : None ,
490506 wire_api : WireApi :: Responses ,
491507 query_params : None ,
492508 http_headers : None ,
0 commit comments