Genkit’s plugin system allows you to create custom model providers to integrate any AI service. Whether you’re using a proprietary API, a custom inference server, or wrapping an existing SDK, you can build a Genkit plugin that provides first-class integration.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/firebase/genkit/llms.txt
Use this file to discover all available pages before exploring further.
When to Build a Custom Provider
Consider building a custom provider when:- You want to integrate a model service not yet supported by Genkit
- You have a proprietary or internal AI API
- You’re running custom model infrastructure
- You want to wrap an existing ML framework
- You need special authentication or request handling
Plugin Architecture
A Genkit plugin provides:- Initialization - Set up clients, validate configuration
- Action Registration - Define available models and embedders
- Action Resolution - Handle dynamic model requests
- Action Listing - Provide discoverable model metadata
Basic Plugin Structure
Simple Plugin Example
Here’s a minimal custom provider:Defining Models
Model Action
A model action implements the interface for generating responses:Model Reference Helper
Provide a helper for creating model references:Request/Response Conversion
Converting Genkit Requests
Converting API Responses
Streaming Support
Implementing Streaming
Tool (Function) Support
Converting Tool Definitions
Handling Tool Responses
See the request/response conversion examples above for handlingtoolRequest and toolResponse parts.
Embedder Support
Defining an Embedder
Advanced Features
Dynamic Model Discovery
List available models from your API:Authentication Handling
Custom Configuration Schema
Error Handling
Complete Example: Simple HTTP API Provider
Using the Custom Provider
Real-World Examples
Study Existing Providers
The best way to learn is by studying existing provider implementations: Simple Provider:~/workspace/source/js/plugins/ollama/src/index.ts- Local model provider
~/workspace/source/js/plugins/anthropic/src/index.ts- Claude provider
~/workspace/source/js/plugins/google-genai/src/googleai/index.ts- Google AI provider~/workspace/source/js/plugins/compat-oai/src/index.ts- OpenAI-compatible provider
Testing Your Provider
Unit Tests
Integration Tests
Best Practices
- Follow naming conventions: Use
provider/model-nameformat - Validate configuration: Check required options in constructor
- Handle errors gracefully: Map API errors to Genkit errors
- Support streaming: When your API supports it
- Document capabilities: Accurately report model capabilities
- Provide type safety: Export TypeScript types for configs
- Test thoroughly: Unit and integration tests
- Version your plugin: Semantic versioning
- Document usage: Provide README with examples
Publishing Your Provider
Once your provider is ready:- Package structure:
- package.json:
- Publish to npm:
Resources
- Genkit Plugin API Documentation
- Model Interface Documentation
- Existing Provider Source Code
- Genkit Discord Community