Skip to main content

Client Overview

The Bifrost client is your main interface for making AI requests. It handles:
  • Request routing to appropriate providers
  • Automatic fallbacks when providers fail
  • Concurrent processing with worker pools
  • Plugin execution for custom middleware
  • MCP tool integration for external capabilities

Core Methods

Chat Completion

The primary method for conversational AI interactions:
Basic Example:

Text Completion

For simple text generation without conversation context:
Basic Example:

MCP Tool Execution

Execute external tools manually for security and control:
📖 Learn More: See MCP Integration for complete tool setup and usage patterns.

Cleanup

Always cleanup resources when done:
Example:

Advanced Request Patterns

Multi-Turn Conversations

Build conversational applications with message history:

Automatic Fallbacks

Ensure reliability with provider fallbacks:

Request Parameters

Fine-tune model behavior with parameters:

Tool Calling

Basic Tool Usage

Enable models to call external functions:

Tool Choice Control

Control when and which tools the model uses:

Multimodal Requests

Image Analysis

Send images for analysis (supported by GPT-4V, Claude, etc.):

Context Management

Context with Timeouts

Control request timeouts and cancellation:

Context with Values

Pass metadata through request context:

Response Handling

Response Structure

Understanding the response format:

Error Handling

Handle different types of errors:

Advanced Configuration

Custom Initialization

Configure client behavior during initialization:

Graceful Cleanup

Always cleanup resources properly:

Testing Client Usage

Unit Tests

Test client methods with mock providers:

Integration Tests

Test with real providers (requires API keys):
— Architecture: For system internals and performance details, see Architecture Documentation.