AI SDK Provider Utilities
Common utility functions for implementing AI SDK providers.
Overview
This crate provides shared functionality for provider implementations, including HTTP header management, request/response handling, and other cross-cutting concerns. These utilities promote code reuse and consistency across different provider implementations.
Features
- Header Management - Merge and manage HTTP headers for API requests
- Reqwest Integration - Optional integration with the reqwest HTTP client
Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
For reqwest integration:
[]
= { = "0.1.0", = ["reqwest"] }
Header Management
The crate provides utilities for merging base headers with request-specific overrides:
use merge_headers;
use HashMap;
let mut base_headers = new;
base_headers.insert;
let mut custom_headers = new;
custom_headers.insert;
let merged = merge_headers;
Reqwest Integration
When using the reqwest feature, you can directly create a reqwest::header::HeaderMap:
use merge_headers_reqwest;
use HashMap;
let mut base_headers = new;
base_headers.insert;
let mut custom_headers = new;
custom_headers.insert;
let headers = merge_headers_reqwest;
// Use directly with reqwest
let response = new
.post
.headers
.json
.send
.await?;
Use Cases
This crate is intended for use by:
- AI SDK provider implementation crates (
ai-sdk-openai,ai-sdk-anthropic, etc.) - Custom provider implementations that want consistent header handling
- Any code that needs to merge HTTP headers with override semantics
License
See the main AI SDK repository for license information.