Skip to content

chore: add with_headers method#245

Closed
b0xtch wants to merge 4 commits into64bit:mainfrom
b0xtch:main
Closed

chore: add with_headers method#245
b0xtch wants to merge 4 commits into64bit:mainfrom
b0xtch:main

Conversation

@b0xtch
Copy link
Copy Markdown

@b0xtch b0xtch commented Jul 19, 2024

Support custom headers required for observability applications

    let client = Client::with_config(
        OpenAIConfig::default()
            .with_api_base(api_base)
            .with_headers(HashMap::from([(
                "Helicone-Auth".to_string(),
                format!("Bearer {}", config_env_var("HELICONE_API_KEY")?),
            )])),
    );

@64bit
Copy link
Copy Markdown
Owner

64bit commented Jul 24, 2024

Thanks for the PR, I'll leave review seperately

api_base: String,
api_key: Secret<String>,
#[serde(deserialize_with = "deserialize_header_map")]
headers: HashMap<String, String>,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use native HeaderMap instead of custom conversion with custom deserializer.

api_key: std::env::var("OPENAI_API_KEY")
.unwrap_or_else(|_| "".to_string())
.into(),
headers: HashMap::new(),
Copy link
Copy Markdown
Owner

@64bit 64bit Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since this is platform independent - this and with_headers could be a nice addition to AzureConfig as well for consistency. Not required though.

@vitorfdl
Copy link
Copy Markdown

vitorfdl commented Apr 8, 2025

Hey, any raeson this is not merged yet ?

@64bit
Copy link
Copy Markdown
Owner

64bit commented Nov 16, 2025

Thanks for the PR!

The latest release has with_header method to enable this behaviour without custom deserialization implementation:

https://docs.rs/async-openai/0.31.0-alpha.7/async_openai/config/struct.OpenAIConfig.html#method.with_header, hence closing.

@64bit 64bit closed this Nov 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants