azureaigateway

package
v1.4.430 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package azureaigateway provides a plugin for Azure API Management (APIM) Gateway fronting multiple AI backends (AWS Bedrock, Azure OpenAI, Google Vertex AI).

Each backend only defines what differs: endpoint path, auth header, request/response format. The shared HTTP plumbing lives in the Client.

Package azureaigateway - Azure OpenAI backend for Azure OpenAI using OpenAI Chat Completions API format

Package azureaigateway - Bedrock backend for AWS Bedrock using Anthropic Messages API format

Package azureaigateway - Vertex AI backend for Google Vertex AI using Gemini API format

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AzureOpenAIBackend

type AzureOpenAIBackend struct {
	// contains filtered or unexported fields
}

AzureOpenAIBackend implements the Backend interface for Azure OpenAI through Azure APIM Gateway

func NewAzureOpenAIBackend

func NewAzureOpenAIBackend(subscriptionKey, apiVersion string) *AzureOpenAIBackend

NewAzureOpenAIBackend creates a new Azure OpenAI backend handler If apiVersion is empty, defaults to "2025-04-01-preview"

func (*AzureOpenAIBackend) AuthHeader

func (b *AzureOpenAIBackend) AuthHeader() (string, string)

AuthHeader returns the Azure OpenAI auth header

func (*AzureOpenAIBackend) BuildEndpoint

func (b *AzureOpenAIBackend) BuildEndpoint(baseURL, deploymentName string) string

BuildEndpoint constructs the Azure OpenAI API endpoint URL API version reference: https://learn.microsoft.com/azure/ai-services/openai/reference

func (*AzureOpenAIBackend) ListModels

func (b *AzureOpenAIBackend) ListModels() ([]string, error)

ListModels returns the list of models available through Azure OpenAI. These are deployment names that must exist in your Azure OpenAI resource.

func (*AzureOpenAIBackend) ParseResponse

func (b *AzureOpenAIBackend) ParseResponse(body []byte) (string, error)

ParseResponse parses Azure OpenAI API response (OpenAI chat completions format)

func (*AzureOpenAIBackend) PrepareRequest

func (b *AzureOpenAIBackend) PrepareRequest(msgs []*chat.ChatCompletionMessage, opts *domain.ChatOptions) ([]byte, error)

PrepareRequest converts messages to Azure OpenAI (OpenAI-compatible) API format

type Backend

type Backend interface {
	// ListModels returns the list of models available for this backend
	ListModels() ([]string, error)

	// BuildEndpoint constructs the full API endpoint URL for the given model
	BuildEndpoint(baseURL, model string) string

	// AuthHeader returns the header name and value for authentication.
	// Each APIM backend uses a different auth header:
	//   Bedrock:      "Authorization", "Bearer <key>"
	//   Azure OpenAI: "api-key", "<key>"
	//   Vertex AI:    "x-goog-api-key", "<key>"
	AuthHeader() (name, value string)

	// PrepareRequest prepares the HTTP request body for this backend's API format
	PrepareRequest(msgs []*chat.ChatCompletionMessage, opts *domain.ChatOptions) ([]byte, error)

	// ParseResponse parses the HTTP response body into text content
	ParseResponse(body []byte) (string, error)
}

Backend defines the interface that all Azure AI Gateway backends must implement. Each backend only provides what is unique to its API format. The shared HTTP mechanics (request execution, error handling, streaming fallback) are handled by the Client.

type BedrockBackend

type BedrockBackend struct {
	// contains filtered or unexported fields
}

BedrockBackend implements the Backend interface for AWS Bedrock through Azure APIM Gateway

func NewBedrockBackend

func NewBedrockBackend(subscriptionKey string) *BedrockBackend

NewBedrockBackend creates a new Bedrock backend handler

func (*BedrockBackend) AuthHeader

func (b *BedrockBackend) AuthHeader() (string, string)

AuthHeader returns the Bedrock auth header (Bearer token)

func (*BedrockBackend) BuildEndpoint

func (b *BedrockBackend) BuildEndpoint(baseURL, model string) string

BuildEndpoint constructs the Bedrock API endpoint URL

func (*BedrockBackend) ListModels

func (b *BedrockBackend) ListModels() ([]string, error)

ListModels returns the list of available Bedrock inference profiles

func (*BedrockBackend) ParseResponse

func (b *BedrockBackend) ParseResponse(body []byte) (string, error)

ParseResponse parses Bedrock API response (Anthropic content blocks)

func (*BedrockBackend) PrepareRequest

func (b *BedrockBackend) PrepareRequest(msgs []*chat.ChatCompletionMessage, opts *domain.ChatOptions) ([]byte, error)

PrepareRequest converts messages to Bedrock API format (Anthropic Messages API). System messages are extracted into the top-level "system" field per the Anthropic API spec.

type Client

type Client struct {
	*plugins.PluginBase
	BackendType     *plugins.SetupQuestion
	GatewayURL      *plugins.SetupQuestion
	SubscriptionKey *plugins.SetupQuestion
	APIVersion      *plugins.SetupQuestion
	// contains filtered or unexported fields
}

Client implements the Azure AI Gateway vendor for Fabric. It supports multiple backends (Bedrock, Azure OpenAI, Vertex AI) through a unified Azure APIM Gateway with shared subscription key authentication.

func NewClient

func NewClient() *Client

NewClient creates a new Azure AI Gateway client

func (*Client) IsConfigured

func (c *Client) IsConfigured() bool

IsConfigured returns true if both gateway URL and subscription key are configured

func (*Client) ListModels

func (c *Client) ListModels() ([]string, error)

ListModels delegates to the active backend

func (*Client) Send

func (c *Client) Send(ctx context.Context, msgs []*chat.ChatCompletionMessage, opts *domain.ChatOptions) (string, error)

Send sends a non-streaming request through the APIM gateway. This is the single implementation of HTTP plumbing shared by all backends.

func (*Client) SendStream

func (c *Client) SendStream(msgs []*chat.ChatCompletionMessage, opts *domain.ChatOptions, channel chan domain.StreamUpdate) error

SendStream falls back to non-streaming (APIM gateway doesn't support SSE pass-through).

NOTE: This method uses context.Background() because the ai.Vendor interface does not accept a context parameter for SendStream. If the caller disconnects, this request will continue until the gateway timeout (300s). A future update to the ai.Vendor interface should add context propagation to SendStream.

type VertexAIBackend

type VertexAIBackend struct {
	// contains filtered or unexported fields
}

VertexAIBackend implements the Backend interface for Google Vertex AI (Gemini) through Azure APIM Gateway.

func NewVertexAIBackend

func NewVertexAIBackend(subscriptionKey string) *VertexAIBackend

NewVertexAIBackend creates a new Vertex AI backend handler

func (*VertexAIBackend) AuthHeader

func (b *VertexAIBackend) AuthHeader() (string, string)

AuthHeader returns the Vertex AI auth header (Google API key via APIM)

func (*VertexAIBackend) BuildEndpoint

func (b *VertexAIBackend) BuildEndpoint(baseURL, model string) string

BuildEndpoint constructs the Vertex AI API endpoint URL Uses /publishers/google/models/{model}:generateContent path per Azure APIM Gateway routing This is the APIM-specific path that proxies to Google's Vertex AI service (differs from direct Vertex AI API which uses /v1beta/models/{model}:generateContent)

func (*VertexAIBackend) ListModels

func (b *VertexAIBackend) ListModels() ([]string, error)

ListModels returns the list of Gemini models available through Vertex AI

func (*VertexAIBackend) ParseResponse

func (b *VertexAIBackend) ParseResponse(body []byte) (string, error)

ParseResponse parses Gemini API response (candidates/content/parts)

func (*VertexAIBackend) PrepareRequest

func (b *VertexAIBackend) PrepareRequest(msgs []*chat.ChatCompletionMessage, opts *domain.ChatOptions) ([]byte, error)

PrepareRequest converts messages to Gemini API format (contents/parts). System messages are extracted into the top-level "systemInstruction" field per the Gemini API spec.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL