Skip to main content

Overview

Backend is an umbrella module that encapsulates a unified way to work with the following functionalities:
  • Chat Models (ChatModel class)
  • Embedding Models (EmbeddingModel class)
  • Audio Models (coming soon)
  • Image Models (coming soon)
BeeAI framework’s backend is designed with a provider-based architecture, allowing you to switch between different AI service providers while maintaining a consistent API.
Supported in Python and TypeScript.

Supported providers

The following table depicts supported providers. Each provider requires specific configuration through environment variables. Ensure all required variables are set before initializing a provider.
NameChatEmbeddingEnvironment Variables
OllamaOLLAMA_CHAT_MODEL
OLLAMA_BASE_URL
OpenAIOPENAI_CHAT_MODEL
OPENAI_EMBEDDING_MODEL
OPENAI_API_BASE
OPENAI_API_KEY
OPENAI_ORGANIZATION
OPENAI_API_HEADERS
IBM watsonx.aiWATSONX_CHAT_MODEL
WATSONX_API_KEY
WATSONX_PROJECT_ID
WATSONX_SPACE_ID
WATSONX_TOKEN
WATSONX_ZENAPIKEY
WATSONX_URL
WATSONX_REGION
AnthropicANTHROPIC_CHAT_MODEL
ANTHROPIC_API_KEY
ANTHROPIC_API_HEADERS
GroqGROQ_CHAT_MODEL
GROQ_EMBEDDING_MODEL
GROQ_API_KEY
Amazon BedrockAWS_CHAT_MODEL
AWS_BEDROCK_API_KEY
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_REGION
AWS_API_HEADERS
Google VertexGOOGLE_VERTEX_CHAT_MODEL
GOOGLE_VERTEX_PROJECT
GOOGLE_VERTEX_LOCATION
GOOGLE_APPLICATION_CREDENTIALS
GOOGLE_APPLICATION_CREDENTIALS_JSON
GOOGLE_CREDENTIALS
GOOGLE_VERTEX_API_HEADERS
Azure OpenAIAZURE_OPENAI_CHAT_MODEL
AZURE_OPENAI_API_KEY
AZURE_OPENAI_API_BASE
AZURE_OPENAI_API_VERSION
AZURE_AD_TOKEN
AZURE_API_TYPE
AZURE_API_HEADERS
xAIXAI_CHAT_MODEL
XAI_API_KEY
Google GeminiGEMINI_CHAT_MODEL
GEMINI_API_KEY
GEMINI_API_HEADERS
MistralAIMISTRALAI_CHAT_MODEL
MISTRALAI_EMBEDDING_MODEL
MISTRALAI_API_KEY
MISTRALAI_API_BASE
TransformersTRANSFORMERS_CHAT_MODEL
HF_TOKEN
MiniMaxMINIMAX_CHAT_MODEL
MINIMAX_API_KEY
MINIMAX_API_BASE
MINIMAX_API_HEADERS
If you don’t see your provider raise an issue here. Meanwhile, you can use the Ollama for local models in Python or TypeScript or the Langchain adapter for hosted providers.
Google Gemini, MistralAI, and Transformers are supported in Python only. The Transformers chat model does not support tool calling.

Backend initialization

The Backend class serves as a central entry point to access models from your chosen provider. This example illustrate how to leverage the framework’s unified interface for different provider model operations by showcasing various interaction patterns including:
  • Basic chat completion
  • Streaming responses with abort functionality
  • Structured output generation
  • Real-time response parsing
  • Tool calling with external APIs
  • Text embedding generation
Explore more provider examples in Python or TypeScript
See the events documentation for more information on standard emitter events.

Chat model

The ChatModel class represents a Chat Language Model and provides methods for text generation, streaming responses, and more. You can initialize a chat model in multiple ways: Method 1: Using the from_name method
Method 2: Directly specifying the provider class

File / Document Inputs (PDF etc.)

You can attach files (e.g. PDFs) to a UserMessage using the MessageFileContent part or the convenience factory UserMessage.from_file. Provide either a remote file_id/URL or an inline base64 data URI (file_data). Optionally specify a MIME format.
Python
These content parts serialize to the flattened schema (legacy nested { "file": {...} } removed):
If neither file_id nor file_data is supplied a validation error is raised.

Chat model configuration

You can configure various parameters for your chat model.

Text generation

The most basic usage is to generate text responses:
Execution parameters (those passed to model.create({...})) take precedent over ones defined via config.

Streaming responses

For applications requiring real-time responses:

Structured generation

Generate structured data according to a schema:

Tool calling

Integrate external tools with your AI model:

Embedding model

The EmbedingModel class provides functionality for generating vector embeddings from text.

Embedding model initialization

You can initialize an embedding model in multiple ways: Method 1: Using the from_name method
Method 2: Directly specifying the provider class

Embedding model usage

Generate embeddings for one or more text strings:

Adding a Provider Using the LangChain Adapter

If your preferred provider isn’t directly supported, you can use the LangChain adapter as a bridge as long as that provider has LangChain compatibility.

Troubleshooting

Common issues and their solutions:
  1. Authentication errors: Ensure all required environment variables are set correctly
  2. Model not found: Verify that the model ID is correct and available for the selected provider

Examples

Python

Explore reference backend implementations in Python

TypeScript

Explore reference backend implementations in TypeScript