11use std:: pin:: Pin ;
22
3- use { async_trait:: async_trait, futures:: StreamExt , tokio_stream:: Stream } ;
3+ use { async_trait:: async_trait, futures:: StreamExt , secrecy :: ExposeSecret , tokio_stream:: Stream } ;
44
55use tracing:: { debug, trace, warn} ;
66
77use crate :: model:: { CompletionResponse , LlmProvider , StreamEvent , ToolCall , Usage } ;
88
99pub struct AnthropicProvider {
10- api_key : String ,
10+ api_key : secrecy :: Secret < String > ,
1111 model : String ,
1212 base_url : String ,
1313 client : reqwest:: Client ,
@@ -16,7 +16,7 @@ pub struct AnthropicProvider {
1616impl AnthropicProvider {
1717 pub fn new ( api_key : String , model : String , base_url : String ) -> Self {
1818 Self {
19- api_key,
19+ api_key : secrecy :: Secret :: new ( api_key ) ,
2020 model,
2121 base_url,
2222 client : reqwest:: Client :: new ( ) ,
@@ -161,7 +161,7 @@ impl LlmProvider for AnthropicProvider {
161161 let http_resp = self
162162 . client
163163 . post ( format ! ( "{}/v1/messages" , self . base_url) )
164- . header ( "x-api-key" , & self . api_key )
164+ . header ( "x-api-key" , self . api_key . expose_secret ( ) )
165165 . header ( "anthropic-version" , "2023-06-01" )
166166 . header ( "content-type" , "application/json" )
167167 . json ( & body)
@@ -221,7 +221,7 @@ impl LlmProvider for AnthropicProvider {
221221 let resp = match self
222222 . client
223223 . post( format!( "{}/v1/messages" , self . base_url) )
224- . header( "x-api-key" , & self . api_key)
224+ . header( "x-api-key" , self . api_key. expose_secret ( ) )
225225 . header( "anthropic-version" , "2023-06-01" )
226226 . header( "content-type" , "application/json" )
227227 . json( & body)
0 commit comments