Add custom headers support for API Management integration
This change adds support for custom HTTP headers in AI inference requests, enabling integration with API Management platforms (Azure APIM, AWS API Gateway, Kong, etc.) and custom request routing/tracking. Features: - New 'custom-headers' input supporting both YAML and JSON formats - Auto-detection of input format for better UX - Header name validation (alphanumeric, hyphens, underscores) - Automatic masking of sensitive headers in logs - Full backward compatibility (optional parameter) Changes: - Added parseCustomHeaders() function in helpers.ts - Updated InferenceRequest interface with optional customHeaders field - Modified simpleInference() and mcpInference() to pass headers to OpenAI client - Added 18 comprehensive test cases - Updated documentation with examples and use cases All 80 tests passing. Zero breaking changes.
This commit is contained in:
@@ -18,6 +18,7 @@ export interface InferenceRequest {
|
||||
temperature?: number
|
||||
topP?: number
|
||||
responseFormat?: {type: 'json_schema'; json_schema: unknown} // Processed response format for the API
|
||||
customHeaders?: Record<string, string> // Custom HTTP headers to include in API requests
|
||||
}
|
||||
|
||||
export interface InferenceResponse {
|
||||
@@ -41,6 +42,7 @@ export async function simpleInference(request: InferenceRequest): Promise<string
|
||||
const client = new OpenAI({
|
||||
apiKey: request.token,
|
||||
baseURL: request.endpoint,
|
||||
defaultHeaders: request.customHeaders || {},
|
||||
})
|
||||
|
||||
const chatCompletionRequest: OpenAI.Chat.Completions.ChatCompletionCreateParams = {
|
||||
@@ -75,6 +77,7 @@ export async function mcpInference(
|
||||
const client = new OpenAI({
|
||||
apiKey: request.token,
|
||||
baseURL: request.endpoint,
|
||||
defaultHeaders: request.customHeaders || {},
|
||||
})
|
||||
|
||||
// Start with the pre-processed messages
|
||||
|
||||
Reference in New Issue
Block a user