feat: add runtime extra HTTP headers support#95
Open
nazq wants to merge 1 commit intograniet:mainfrom
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds runtime-configurable HTTP headers support for LLM providers, enabling use cases like Cloudflare Access authentication. The PR also includes streaming with tools functionality from PR #94.
Key Changes:
- Added
extra_headers()builder method to configure runtime HTTP headers - Implemented
chat_stream_with_tools()for streaming responses with tool call support - Added
StreamChunkenum for unified streaming events (text, tool calls, completion)
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/builder.rs |
Added extra_headers field and builder method; passed to OpenAI and Cohere backends |
src/providers/openai_compatible.rs |
Stored extra_headers field; applied headers to all chat/streaming requests; implemented chat_stream_with_tools() with SSE parsing |
src/backends/openai.rs |
Passed extra_headers to provider; added extra_headers to hosted tools endpoint; delegated chat_stream_with_tools() to provider |
src/backends/mistral.rs |
Added None for extra_headers parameter (not exposed) |
src/backends/groq.rs |
Added None for extra_headers parameter (not exposed) |
src/backends/cohere.rs |
Added None for extra_headers parameter (not exposed) |
src/backends/huggingface.rs |
Added None for extra_headers parameter (not exposed) |
src/backends/openrouter.rs |
Added None for extra_headers parameter (not exposed) |
src/backends/anthropic.rs |
Implemented chat_stream_with_tools() with Anthropic-specific SSE parsing; handles empty tool arguments correctly |
src/chat/mod.rs |
Added StreamChunk enum and chat_stream_with_tools() trait method |
src/resilient_llm.rs |
Added resilient wrappers for new streaming methods |
tests/test_backends.rs |
Added comprehensive integration tests for streaming with tools (Anthropic backend) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Owner
|
Hey @nazq, thanks for your work. Could you resolve the conflict? |
Contributor
Author
|
Sure. Give me a couple hours |
33aff7d to
ae26883
Compare
Contributor
Author
Done |
Add extra_headers option to LLMBuilder for custom HTTP headers in all requests. Useful for custom authentication like Cloudflare Access tokens. - Add extra_headers field and builder method to LLMBuilder - Add extra_headers to OpenAICompatibleProvider and apply in all request methods - Pass extra_headers from builder through OpenAI backend - Update all other OpenAI-compatible backends with None default - Add unit tests for extra_headers functionality
ae26883 to
198ad7a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extra_headers()builder method toLLMBuilderfor runtime-configurable HTTP headersNote: This PR is based on #94 (streaming with tools support) because the new
chat_stream_with_tools()methods also make HTTP requests that need extra headers support.Use Case
Changes
src/builder.rs- Addedextra_headersfield and builder methodsrc/providers/openai_compatible.rs- Store and apply extra headers in requestssrc/backends/openai.rs- Pass extra headers to providerNonefor compatibilityTest plan