OpenAI-compatible plugin
The OpenAI-Compatible API package (genkit-plugin-compat-oai) provides a unified interface for accessing multiple AI providers that implement OpenAI’s API specification. This includes OpenAI and other compatible services.
Overview
Section titled “Overview”The compat_oai package serves as a foundation for building plugins that work with OpenAI-compatible APIs. It includes:
- Base Implementation: Common functionality for OpenAI-compatible APIs
- OpenAI Plugin: Direct access to OpenAI’s models and embeddings
- Extensible Framework: Build custom plugins for other compatible providers
Prerequisites
Section titled “Prerequisites”Depending on which provider you use, you’ll need:
- OpenAI: API key from OpenAI API Keys page
- Other providers: API keys from the respective services
Installation
Section titled “Installation”uv add genkit-plugin-compat-oaiConfiguration
Section titled “Configuration”Use with Compatible Providers
Section titled “Use with Compatible Providers”from genkit import Genkitfrom genkit.plugins.compat_oai import OpenAI
# Custom base URL for OpenAI-compatible servicesai = Genkit( plugins=[ OpenAI( api_key='YOUR_API_KEY', base_url='https://your-custom-endpoint.com/v1', organization='your-org-id', # Optional default_headers={'Custom-Header': 'value'}, # Optional ) ],)Common Configuration
Section titled “Common Configuration”OpenAI-compatible configuration options are supported:
from genkit import Genkitfrom genkit.plugins.compat_oai import OpenAI, openai_model
ai = Genkit(plugins=[OpenAI()])
response = await ai.generate( model=openai_model('gpt-4o'), prompt='Your prompt here', config={ 'temperature': 0.7, 'max_tokens': 1000, 'top_p': 0.9, },)