Skip to content

Commit c0b9a3d

Browse files
docs: documentation fixes and updates
1 parent 3114f35 commit c0b9a3d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1001
-593
lines changed

core/schemas/chatcompletions.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type BifrostChatRequest struct {
1616
Fallbacks []Fallback `json:"fallbacks,omitempty"`
1717
}
1818

19+
// BifrostChatResponse represents the complete result from a chat completion request.
1920
type BifrostChatResponse struct {
2021
ID string `json:"id"`
2122
Choices []BifrostResponseChoice `json:"choices"`
@@ -203,12 +204,12 @@ type ChatToolFunction struct {
203204

204205
// ToolFunctionParameters represents the parameters for a function definition.
205206
type ToolFunctionParameters struct {
206-
Type string `json:"type"` // Type of the parameters
207-
Description *string `json:"description,omitempty"` // Description of the parameters
208-
Required []string `json:"required,omitempty"` // Required parameter names
207+
Type string `json:"type"` // Type of the parameters
208+
Description *string `json:"description,omitempty"` // Description of the parameters
209+
Required []string `json:"required,omitempty"` // Required parameter names
209210
Properties *map[string]interface{} `json:"properties,omitempty"` // Parameter properties
210-
Enum []string `json:"enum,omitempty"` // Enum values for the parameters
211-
AdditionalProperties *bool `json:"additionalProperties,omitempty"` // Whether to allow additional properties
211+
Enum []string `json:"enum,omitempty"` // Enum values for the parameters
212+
AdditionalProperties *bool `json:"additionalProperties,omitempty"` // Whether to allow additional properties
212213
}
213214

214215
type ChatToolCustom struct {

docs/architecture/framework/pricing.mdx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ Calculate costs from a Bifrost response:
109109
// Calculate cost for a completed request
110110
cost := pricingManager.CalculateCost(
111111
result, // *schemas.BifrostResponse
112-
schemas.OpenAI, // provider
113-
"gpt-4", // model
114-
schemas.ChatCompletionRequest, // request type
115112
)
116113

117114
logger.Info("Request cost: $%.6f", cost)
@@ -147,9 +144,6 @@ For workflows that implement semantic caching, use cache-aware cost calculation:
147144
// This automatically handles cache hits/misses and embedding costs
148145
cost := pricingManager.CalculateCostWithCacheDebug(
149146
result, // *schemas.BifrostResponse with cache debug info
150-
schemas.Anthropic, // provider
151-
"claude-3-sonnet", // model
152-
schemas.ChatCompletionRequest, // request type
153147
)
154148

155149
// Cache hits return 0 for direct hits, embedding cost for semantic matches

docs/docs.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,18 @@
9191
"features/tracing",
9292
"features/telemetry",
9393
"features/observability",
94-
"features/governance",
9594
"features/semantic-caching",
9695
"features/custom-providers",
96+
{
97+
"group": "Governance",
98+
"icon": "user-lock",
99+
"pages": [
100+
"features/governance/virtual-keys",
101+
"features/governance/budget-and-limits",
102+
"features/governance/routing",
103+
"features/governance/mcp-tools"
104+
]
105+
},
97106
{
98107
"group": "Plugins",
99108
"icon": "puzzle-piece",
@@ -110,7 +119,7 @@
110119
"pages": [
111120
"enterprise/guardrails",
112121
"enterprise/clustering",
113-
"enterprise/governance",
122+
"enterprise/advanced-governance",
114123
"enterprise/mcp-with-fa",
115124
"enterprise/vault-support",
116125
"enterprise/invpc-deployments",

docs/enterprise/governance.mdx renamed to docs/enterprise/advanced-governance.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Governance"
2+
title: "Advanced Governance"
33
description: "Advanced governance features with enhanced security, compliance reporting, audit trails, and enterprise-grade access controls for large-scale deployments."
44
icon: "shield-check"
55
---
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
title: "Budget and Limits"
3+
description: "Enterprise-grade budget management and cost control with hierarchical budget allocation through virtual keys, teams, and customers."
4+
icon: "money-bills"
5+
---
6+
7+
## Overview
8+
9+
Budgeting and rate limiting are a core feature of Bifrost's governance system managed through [Virtual Keys](./virtual-keys).
10+
11+
Bifrost's budget management system provides comprehensive cost control and financial governance for enterprise AI deployments. It operates through a **hierarchical budget structure** that enables granular cost management, usage tracking, and financial oversight across your entire organization.
12+
13+
**Core Hierarchy:**
14+
```
15+
Customer (has independent budget)
16+
↓ (one-to-many)
17+
Team (has independent budget)
18+
↓ (one-to-many)
19+
Virtual Key (has independent budget + rate limits)
20+
21+
OR
22+
23+
Customer (has independent budget)
24+
↓ (direct attachment)
25+
Virtual Key (has independent budget + rate limits)
26+
27+
OR
28+
29+
Virtual Key (standalone - has independent budget + rate limits)
30+
```
31+
32+
**Key Capabilities:**
33+
- **Virtual Keys** - Primary access control via `x-bf-vk` header (exclusive team OR customer attachment)
34+
- **Budget Management** - Independent budget limits at each hierarchy level with cumulative checking
35+
- **Rate Limiting** - Request and token-based throttling (VK-level only)
36+
- **Model/Provider Filtering** - Granular access control per virtual key
37+
- **Usage Tracking** - Real-time monitoring and audit trails
38+
- **Audit Headers** - Optional team and customer identification
39+
40+
---
41+
42+
## Budget Management
43+
44+
### Cost Calculation
45+
46+
Bifrost automatically calculates costs based on:
47+
- **Provider Pricing** - Real-time model pricing data
48+
- **Token Usage** - Input + output tokens from API responses
49+
- **Request Type** - Different pricing for chat, text, embedding, speech, transcription
50+
- **Cache Status** - Reduced costs for cached responses
51+
- **Batch Operations** - Volume discounts for batch requests
52+
53+
All cost calculation details are covered in [Architecture > Framework > Pricing](../../architecture/framework/pricing).
54+
55+
### Budget Checking Flow
56+
57+
When a request is made with a a virtual key, Bifrost checks **all applicable budgets independently** in the hierarchy. Each budget must have sufficient remaining balance for the request to proceed.
58+
59+
**Checking Sequence:**
60+
61+
**For VK → Team → Customer:**
62+
```
63+
1. ✓ VK Budget (if VK has budget)
64+
2. ✓ Team Budget (if VK's team has budget)
65+
3. ✓ Customer Budget (if team's customer has budget)
66+
```
67+
68+
**For VK → Customer (direct):**
69+
```
70+
1. ✓ VK Budget (if VK has budget)
71+
2. ✓ Customer Budget (if VK's customer has budget)
72+
```
73+
74+
**For Standalone VK:**
75+
```
76+
1. ✓ VK Budget (if VK has budget)
77+
```
78+
79+
**Important Notes:**
80+
- **All applicable budgets must pass** - any single budget failure blocks the request
81+
- **Budgets are independent** - each tracks its own usage and limits
82+
- **Costs are deducted from all applicable budgets** - same cost applied to each level
83+
- **Rate limits checked only at VK level** - teams and customers have no rate limits
84+
85+
**Example:**
86+
- VK budget: $9/$10 remaining ✓
87+
- Team budget: $15/$20 remaining ✓
88+
- Customer budget: $45/$50 remaining ✓
89+
- **Result: Allowed** (no budget is exceeded)
90+
- After request:
91+
- Request cost: $2
92+
- Updated VK=$11/$10, Team=$17/$20, Customer=$47/$50
93+
- Then the next request will be blocked.
94+
95+
## Rate Limiting
96+
97+
Rate limits protect your system from abuse and manage traffic by setting thresholds on request frequency and token usage over a specific time window. Unlike budgets, rate limits are configured **exclusively at the Virtual Key level**.
98+
99+
Bifrost supports two types of rate limits that work in parallel:
100+
- **Request Limits**: Control the maximum number of API calls that can be made within a set duration (e.g., 100 requests per minute).
101+
- **Token Limits**: Control the maximum number of tokens (prompt + completion) that can be processed within a set duration (e.g., 50,000 tokens per hour).
102+
103+
For a request to be allowed, it must pass both the request limit and the token limit checks.
104+
105+
## Reset Durations
106+
107+
Budgets and rate limits support flexible reset durations:
108+
109+
**Format Examples:**
110+
- `1m` - 1 minute
111+
- `5m` - 5 minutes
112+
- `1h` - 1 hour
113+
- `1d` - 1 day
114+
- `1w` - 1 week
115+
- `1M` - 1 month
116+
117+
**Common Patterns:**
118+
- **Rate Limits**: `1m`, `1h`, `1d` for request throttling
119+
- **Budgets**: `1d`, `1w`, `1M` for cost control
120+
121+
---
122+
123+
## Next Steps
124+
125+
- **[Routing](./routing)** - Direct requests to specific AI models, providers, and keys using Virtual Keys.
126+
- **[MCP Tool Filtering](./mcp-tools)** - Manage MCP clients/tools for virtual keys.
127+
- **[Tracing](../tracing)** - Audit trails and request tracking
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
---
2+
title: "MCP Tool Filtering"
3+
description: "Control which MCP tools are available for each Virtual Key."
4+
icon: "grid-2"
5+
---
6+
7+
## Overview
8+
9+
MCP Tool Filtering allows you to control which tools are available to AI models on a per-request basis using Virtual Keys (VKs). By configuring a VirtualKey, you can create a strict allow-list of MCP clients and tools, ensuring that only approved tools can be executed.
10+
11+
Make sure you have at least one MCP client set up. Read more about it [here](../mcp).
12+
13+
## How It Works
14+
15+
The filtering logic is determined by the Virtual Key's configuration:
16+
17+
1. **No MCP Configuration on Virtual Key (Default)**
18+
- If a Virtual Key has no specific MCP configurations, all tools from all enabled MCP clients are available by default.
19+
- In this state, a user can still manually filter tools for a single request by passing the `x-bf-mcp-include-tools` header.
20+
21+
2. **With MCP Configuration on Virtual Key**
22+
- When you configure MCP clients on a Virtual Key, its settings take full precedence.
23+
- Bifrost automatically generates an `x-bf-mcp-include-tools` header based on your VK configuration. This acts as a strict allow-list for the request.
24+
- This generated header **overrides** any `x-bf-mcp-include-tools` header that might have been sent manually with the request.
25+
26+
For each MCP client associated with a Virtual Key, you can specify the allowed tools:
27+
- **Select specific tools**: Only the chosen tools from that client will be available.
28+
- **Use `*` wildcard**: All available tools from that client will be permitted.
29+
- **Leave tool list empty**: All tools from that client will be **blocked**.
30+
- **Do not configure a client**: All tools from that client will be **blocked** (if other clients are configured).
31+
32+
## Setting MCP Tool Restrictions
33+
34+
<Tabs group="mcp-tool-restrictions">
35+
<Tab title="Web UI">
36+
37+
You can configure which tools a Virtual Key has access to via the UI.
38+
39+
1. Go to **Virtual Keys** page.
40+
2. Create/Edit virtual key
41+
![Virtual Key MCP Tool Restrictions](../../media/ui-virtual-key-mcp-filter.png)
42+
3. In **MCP Client Configurations** section, add the MCP client you want to restrict the VK to
43+
4. Add the tools you want to restrict the VK to, or leave it blank to allow all tools for this client
44+
5. Click on the **Save** button
45+
46+
</Tab>
47+
<Tab title="API">
48+
49+
You can configure this via the REST API when creating (`POST`) or updating (`PUT`) a virtual key.
50+
51+
**Create Virtual Key:**
52+
```bash
53+
curl -X POST http://localhost:8080/api/governance/virtual-keys \
54+
-H "Content-Type: application/json" \
55+
-d '{
56+
"name": "vk-for-billing-support",
57+
"mcp_configs": [
58+
{
59+
"mcp_client_name": "billing-client",
60+
"tools_to_execute": ["check-status"]
61+
},
62+
{
63+
"mcp_client_name": "support-client",
64+
"tools_to_execute": ["*"]
65+
}
66+
]
67+
}'
68+
```
69+
70+
**Update Virtual Key:**
71+
```bash
72+
curl -X PUT http://localhost:8080/api/governance/virtual-keys/{vk_id} \
73+
-H "Content-Type: application/json" \
74+
-d '{
75+
"mcp_configs": [
76+
{
77+
"mcp_client_name": "billing-client",
78+
"tools_to_execute": ["check-status"]
79+
},
80+
{
81+
"mcp_client_name": "support-client",
82+
"tools_to_execute": ["*"]
83+
}
84+
]
85+
}'
86+
```
87+
88+
**Behavior:**
89+
- The virtual key can only access the `check-status` tool from `billing-client`.
90+
- It can access all tools from `support-client`.
91+
- Any other MCP client is implicitly blocked for this key.
92+
93+
</Tab>
94+
95+
<Tab title="config.json">
96+
97+
You can also define MCP tool restrictions directly in your `config.json` file. The `mcp_configs` array under a virtual key should reference the MCP client by name.
98+
99+
```json
100+
{
101+
"governance": {
102+
"virtual_keys": [
103+
{
104+
"id": "vk-billing-support-only",
105+
"name": "VK for Billing and Support",
106+
"mcp_configs": [
107+
{
108+
"mcp_client_name": "billing-client",
109+
"tools_to_execute": ["check-status"]
110+
},
111+
{
112+
"mcp_client_name": "support-client",
113+
"tools_to_execute": ["*"]
114+
}
115+
]
116+
}
117+
]
118+
}
119+
}
120+
```
121+
</Tab>
122+
</Tabs>
123+
124+
## Example Scenario
125+
126+
**Available MCP Clients & Tools:**
127+
- **`billing-client`**: with tools `[create-invoice, check-status]`
128+
- **`support-client`**: with tools `[create-ticket, get-faq]`
129+
130+
<Tabs>
131+
<Tab title="VK with Full Access">
132+
**Configuration:**
133+
- `billing-client` -> Allowed Tools: `[*]` (wildcard)
134+
- `support-client` -> Allowed Tools: `[*]` (wildcard)
135+
136+
**Result:**
137+
A request with this Virtual Key can access all four tools: `create-invoice`, `check-status`, `create-ticket`, and `get-faq`.
138+
139+
</Tab>
140+
<Tab title="VK with Partial Access">
141+
**Configuration:**
142+
- `billing-client` -> Allowed Tools: `[check-status]`
143+
- `support-client` -> Not configured
144+
145+
**Result:**
146+
A request with this Virtual Key can only access the `check-status` tool. All other tools are blocked.
147+
148+
</Tab>
149+
<Tab title="VK with No Tools">
150+
**Configuration:**
151+
- `billing-client` -> Allowed Tools: `[]` (empty list)
152+
153+
**Result:**
154+
A request with this Virtual Key cannot access any tools. All tools from all clients are blocked.
155+
</Tab>
156+
</Tabs>
157+
158+
<Note>
159+
When a Virtual Key has MCP configurations, it dynamically generates the `x-bf-mcp-include-tools` header. This ensures that the VK's rules are always enforced and will override any manual header sent by the user. Though you can still use `x-bf-mcp-include-clients` header to filter the MCP clients per request.
160+
</Note>

0 commit comments

Comments
 (0)