Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/providers/openai/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ func HandleOpenAITextCompletionStreaming(

var finishReason *string
var messageID string
var created int
lastChunkTime := startTime

for {
Expand Down Expand Up @@ -709,6 +710,9 @@ func HandleOpenAITextCompletionStreaming(
if response.ID != "" && messageID == "" {
messageID = response.ID
}
if response.Created != 0 && created == 0 {
created = response.Created
}

// Handle regular content chunks
if choice.TextCompletionResponseChoice != nil && choice.TextCompletionResponseChoice.Text != nil {
Expand All @@ -731,7 +735,7 @@ func HandleOpenAITextCompletionStreaming(
}
}

response := providerUtils.CreateBifrostTextCompletionChunkResponse(messageID, usage, finishReason, chunkIndex, schemas.TextCompletionStreamRequest, request.Model)
response := providerUtils.CreateBifrostTextCompletionChunkResponse(messageID, usage, finishReason, chunkIndex, schemas.TextCompletionStreamRequest, request.Model, created)
if postResponseConverter != nil {
response = postResponseConverter(response)
if response == nil {
Expand Down
10 changes: 6 additions & 4 deletions core/providers/replicate/replicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,10 @@ func (provider *ReplicateProvider) TextCompletionStream(ctx *schemas.BifrostCont
// Create a streaming chunk with text completion response
text := eventData
response := &schemas.BifrostTextCompletionResponse{
ID: messageID,
Model: request.Model,
Object: "text_completion",
ID: messageID,
Model: request.Model,
Created: int(ParseReplicateTimestamp(prediction.CreatedAt)),
Object: "text_completion",
Choices: []schemas.BifrostResponseChoice{
{
Index: 0,
Expand Down Expand Up @@ -743,7 +744,8 @@ func (provider *ReplicateProvider) TextCompletionStream(ctx *schemas.BifrostCont
finishReason,
chunkIndex,
schemas.TextCompletionStreamRequest,
request.Model)
request.Model,
int(ParseReplicateTimestamp(prediction.CreatedAt)))

// Set raw request if enabled
if providerUtils.ShouldSendBackRawRequest(ctx, provider.sendBackRawRequest) {
Expand Down
7 changes: 4 additions & 3 deletions core/providers/replicate/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ func (response *ReplicatePredictionResponse) ToBifrostTextCompletionResponse() *

// Initialize Bifrost response
bifrostResponse := &schemas.BifrostTextCompletionResponse{
ID: response.ID,
Model: response.Model,
Object: "text_completion",
ID: response.ID,
Model: response.Model,
Created: int(ParseReplicateTimestamp(response.CreatedAt)),
Object: "text_completion",
}

// Convert output to text
Expand Down
10 changes: 6 additions & 4 deletions core/providers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2740,12 +2740,14 @@ func CreateBifrostTextCompletionChunkResponse(
currentChunkIndex int,
requestType schemas.RequestType,
model string,
created int,
) *schemas.BifrostTextCompletionResponse {
response := &schemas.BifrostTextCompletionResponse{
ID: id,
Model: model,
Object: "text_completion",
Usage: usage,
ID: id,
Model: model,
Created: created,
Object: "text_completion",
Usage: usage,
Choices: []schemas.BifrostResponseChoice{
{
FinishReason: finishReason,
Expand Down
4 changes: 4 additions & 0 deletions core/schemas/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2582,6 +2582,7 @@ func (cr *BifrostChatResponse) ToBifrostTextCompletionResponse() *BifrostTextCom
return &BifrostTextCompletionResponse{
ID: cr.ID,
Model: cr.Model,
Created: cr.Created,
Object: "text_completion",
SystemFingerprint: cr.SystemFingerprint,
Usage: cr.Usage,
Expand All @@ -2605,6 +2606,7 @@ func (cr *BifrostChatResponse) ToBifrostTextCompletionResponse() *BifrostTextCom
return &BifrostTextCompletionResponse{
ID: cr.ID,
Model: cr.Model,
Created: cr.Created,
Object: "text_completion",
SystemFingerprint: cr.SystemFingerprint,
Choices: []BifrostResponseChoice{
Expand Down Expand Up @@ -2654,6 +2656,7 @@ func (cr *BifrostChatResponse) ToBifrostTextCompletionResponse() *BifrostTextCom
return &BifrostTextCompletionResponse{
ID: cr.ID,
Model: cr.Model,
Created: cr.Created,
Object: "text_completion",
SystemFingerprint: cr.SystemFingerprint,
Choices: []BifrostResponseChoice{
Expand Down Expand Up @@ -2684,6 +2687,7 @@ func (cr *BifrostChatResponse) ToBifrostTextCompletionResponse() *BifrostTextCom
return &BifrostTextCompletionResponse{
ID: cr.ID,
Model: cr.Model,
Created: cr.Created,
Object: "text_completion",
SystemFingerprint: cr.SystemFingerprint,
Usage: cr.Usage,
Expand Down
3 changes: 2 additions & 1 deletion core/schemas/textcompletions.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (r *BifrostTextCompletionRequest) ToBifrostChatRequest() *BifrostChatReques
type BifrostTextCompletionResponse struct {
ID string `json:"id"`
Choices []BifrostResponseChoice `json:"choices"`
Created int `json:"created,omitempty"` // The Unix timestamp (in seconds).
Comment thread
sammaji marked this conversation as resolved.
Resolved
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Model string `json:"model"`
Object string `json:"object"` // "text_completion" (same for text completion stream)
SystemFingerprint string `json:"system_fingerprint"`
Expand Down Expand Up @@ -134,7 +135,7 @@ type TextCompletionParameters struct {

// Dynamic parameters that can be provider-specific, they are directly
// added to the request as is.
ExtraParams map[string]interface{} `json:"-"`
ExtraParams map[string]any `json:"-"`
}

// TextCompletionLogProb represents log probability information for text completion.
Expand Down
1 change: 1 addition & 0 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"providers/supported-providers/overview",
"providers/supported-providers/anthropic",
"providers/supported-providers/azure",
"providers/supported-providers/azure-model-router",
"providers/supported-providers/bedrock",
"providers/supported-providers/bedrock-mantle",
"providers/supported-providers/cerebras",
Expand Down
129 changes: 129 additions & 0 deletions docs/providers/supported-providers/azure-model-router.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
title: "Azure Model Router"
description: "Use Azure model-router deployments with Bifrost - native Chat Completions support and a custom-provider workaround for Responses"
icon: "microsoft"
---

## Overview

Azure model router is an Azure OpenAI deployment family that automatically picks the best underlying model for a request. Bifrost's native Azure provider supports model-router deployments for Chat Completions today.

The Responses API is not yet exposed for model-router deployments through the native Azure provider. Until that lands, you can reach model-router's Responses endpoint directly through your Azure AI Foundry project by configuring **Azure Foundry as a custom provider**, as described below.

<Note>
This page covers model-router specifically. For general endpoint setup, authentication, aliases, and deployment configuration on the native Azure provider, see the main [Azure provider guide](./azure).
</Note>

### Supported operations

| Operation | Support | Notes |
| --- | --- | --- |
| Chat Completions | ✅ | Native Azure provider or Azure Foundry custom provider |
| Chat Completions (stream) | ✅ | Native Azure provider or Azure Foundry custom provider |
| Responses API | ⚠️ | Requires adding Azure Foundry as a custom-provider |
| Responses API (stream) | ⚠️ | Requires adding Azure Foundry as a custom-provider |

---

## Adding Azure Foundry as a custom provider

Azure AI Foundry projects expose an OpenAI-Responses-API-shaped endpoint (`*.ai.azure.com/api/projects/<project>/openai/v1/responses`) that is distinct from the classic Azure OpenAI resource endpoint (`*.openai.azure.com`) used by the native Azure provider. You can reach it by creating a [custom provider](../custom-providers) named e.g. `azure-foundry` with `base_provider_type: "openai"` and a full-URL [request path override](../custom-providers#request-path-overrides) for the `responses` and `responses_stream` request types. A full URL in `request_path_overrides` bypasses `base_url` entirely, so requests go straight to your Azure AI Foundry project's Responses endpoint.

<Tabs group="config-method">
<Tab title="Web UI">

![Custom Provider Configuration Interface](../../media/ui-custom-provider.png)

1. Go to **Providers** in the sidebar and click **Add New Provider**.
2. Name the provider `azure-foundry` (or similar).
3. Set **Base Format** to **OpenAI**.
4. Set **Base URL** to `https://<your-resource>.ai.azure.com/openai`.
5. Under **Allowed Request Types**, toggle on **Responses** and **Responses Stream**.
6. Click the settings icon next to each and enter the full Azure AI Foundry Responses URL in **Custom Path or URL**:
`https://<your-resource>.ai.azure.com/api/projects/<your-project>/openai/v1/responses`
7. Add your Azure API key and save.

</Tab>

<Tab title="API">
Refer to the API documentation for [Provider Keys Management](https://docs.getbifrost.ai/api-reference/providers/create-a-key-for-a-provider).
</Tab>
<Tab title="config.json">

```json
{
"providers": {
"azure-foundry": {
"keys": [
{
"name": "azure-foundry-key-1",
"value": "env.AZURE_API_KEY",
"models": ["*"],
"weight": 1.0
}
],
"network_config": {
"base_url": "https://<your-resource>.ai.azure.com/openai"
},
"custom_provider_config": {
"base_provider_type": "openai",
"allowed_requests": {
"responses": true,
"responses_stream": true
},
"request_path_overrides": {
"responses": "https://<your-resource>.ai.azure.com/api/projects/<your-project>/openai/v1/responses",
"responses_stream": "https://<your-resource>.ai.azure.com/api/projects/<your-project>/openai/v1/responses"
}
}
}
}
}
```

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `custom_provider_config.base_provider_type` | string | Yes | Must be `openai` so requests are shaped as OpenAI-compatible calls |
| `custom_provider_config.allowed_requests` | object | No | Restricts this provider to only the request types you enable |
| `custom_provider_config.request_path_overrides` | object | No | Full URL per request type; bypasses `network_config.base_url` |
| `network_config.base_url` | string | No | Used for any request type without a full-URL override |

</Tab>
</Tabs>

<Note>
If you also want Chat Completions routed through this same custom provider instead of the native Azure provider, enable `chat_completion` / `chat_completion_stream` in `allowed_requests` and add matching entries in `request_path_overrides`. Otherwise, keep using the native Azure provider for Chat Completions and this custom provider only for Responses.
</Note>

---

## Usage

Call the Responses endpoint using the `azure-foundry` custom provider and your model-router deployment name:

```bash
curl -X POST http://localhost:8080/v1/responses \
-H "Content-Type: application/json" \
-d '{
"model": "azure-foundry/model-router",
"input": "Write a short haiku about gateways."
}'
```

<Note>
If you need to inspect provider-specific extra parameters, enable [Send Back Raw Response](/providers/request-options#send-back-raw-response). If you do not want those raw bytes persisted in logs, also set [Store Raw Request/Response](/providers/request-options#store-raw-request/response).
</Note>

---

## Limitations

- Chat Completions for model-router deployments works through the native Azure provider; no extra configuration is needed.
- Responses support for model-router requires the custom-provider workaround on this page until native support is added to the Azure provider.
- This page does not change Azure authentication or endpoint setup for the native Azure provider - see the [Azure provider guide](./azure) for that.

## Related docs

- [Azure](./azure)
- [Custom Providers](../custom-providers)
- [Request Options](/providers/request-options)
Loading