| Crates.io | ai-sdk-provider-utils |
| lib.rs | ai-sdk-provider-utils |
| version | 0.3.0 |
| created_at | 2025-11-23 05:27:55.923526+00 |
| updated_at | 2025-11-23 06:16:30.779639+00 |
| description | Utility functions and helpers for AI SDK providers |
| homepage | |
| repository | https://github.com/khongtrunght/ai-sdk-rust |
| max_upload_size | |
| id | 1946133 |
| size | 50,149 |
Common utility functions for implementing AI SDK providers.
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.
Add this to your Cargo.toml:
[dependencies]
ai-sdk-provider-utils = "0.1.0"
For reqwest integration:
[dependencies]
ai-sdk-provider-utils = { version = "0.1.0", features = ["reqwest"] }
The crate provides utilities for merging base headers with request-specific overrides:
use ai_sdk_provider_utils::merge_headers;
use std::collections::HashMap;
let mut base_headers = HashMap::new();
base_headers.insert("Authorization".to_string(), "Bearer token".to_string());
let mut custom_headers = HashMap::new();
custom_headers.insert("X-Custom-Header".to_string(), "value".to_string());
let merged = merge_headers(base_headers, Some(&custom_headers));
When using the reqwest feature, you can directly create a reqwest::header::HeaderMap:
use ai_sdk_provider_utils::merge_headers_reqwest;
use std::collections::HashMap;
let mut base_headers = HashMap::new();
base_headers.insert("Authorization".to_string(), "Bearer token".to_string());
let mut custom_headers = HashMap::new();
custom_headers.insert("X-Custom-Header".to_string(), "value".to_string());
let headers = merge_headers_reqwest(base_headers, Some(&custom_headers));
// Use directly with reqwest
let response = reqwest::Client::new()
.post("https://api.example.com/generate")
.headers(headers)
.json(&request_body)
.send()
.await?;
This crate is intended for use by:
ai-sdk-openai, ai-sdk-anthropic, etc.)See the main AI SDK repository for license information.