Skip to main content
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.

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:
  1. Initialization - Set up clients, validate configuration
  2. Action Registration - Define available models and embedders
  3. Action Resolution - Handle dynamic model requests
  4. 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 handling toolRequest 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
Medium Complexity:
  • ~/workspace/source/js/plugins/anthropic/src/index.ts - Claude provider
Advanced 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

  1. Follow naming conventions: Use provider/model-name format
  2. Validate configuration: Check required options in constructor
  3. Handle errors gracefully: Map API errors to Genkit errors
  4. Support streaming: When your API supports it
  5. Document capabilities: Accurately report model capabilities
  6. Provide type safety: Export TypeScript types for configs
  7. Test thoroughly: Unit and integration tests
  8. Version your plugin: Semantic versioning
  9. Document usage: Provide README with examples

Publishing Your Provider

Once your provider is ready:
  1. Package structure:
  1. package.json:
  1. Publish to npm:

Resources

Next Steps