Availability
| Edition | Deployment Type |
|---|---|
| Community & Enterprise | Self-Managed, Hybrid |
pkg/plugin_sdk, which automatically detects the Gateway runtime and provides access to universal services (KV storage, logging) and Gateway-specific services (app management, budget status).
Plugin Capabilities
Edge Gateway plugins implement one or more of these capability interfaces:1. PreAuthHandler
Interface:PreAuthHandler
Method: HandlePreAuth(ctx Context, req *pb.EnrichedRequest) (*pb.PluginResponse, error)
Executes before authentication. Use for:
- Request validation and early rejection
- Request enrichment with metadata
- Header modification
- Logging and auditing
examples/plugins/gateway/request_enricher/
2. AuthHandler
Interface:AuthHandler
Method: HandleAuth(ctx Context, req *pb.EnrichedRequest) (*pb.PluginResponse, error)
Replaces default token authentication. Use for:
- Custom authentication schemes (OAuth, JWT, API keys)
- Integration with external identity providers
- Multi-factor authentication
- Custom authorization logic
ctx.Services.Gateway().ValidateCredential()
3. PostAuthHandler
Interface:PostAuthHandler
Method: HandlePostAuth(ctx Context, req *pb.EnrichedRequest) (*pb.PluginResponse, error)
Executes after authentication. Most common capability for gateway plugins. Use for:
- Enriching requests with user-specific data
- Per-user request transformation
- Access control enforcement
- Usage quota checks
examples/plugins/gateway/request_enricher/
4. ResponseHandler
Interface:ResponseHandler
Methods:
OnBeforeWriteHeaders(ctx Context, req *pb.ResponseWriteRequest) (*pb.ResponseWriteResponse, error)OnBeforeWrite(ctx Context, req *pb.ResponseWriteRequest) (*pb.ResponseWriteResponse, error)
- OnBeforeWriteHeaders: Modify response headers
- OnBeforeWrite: Modify response body
- Response filtering and content moderation
- Response transformation and formatting
- Injecting additional metadata
- Response validation
examples/plugins/gateway/response_modifier/
5. DataCollector
Interface:DataCollector
Methods:
HandleProxyLog(ctx Context, log *pb.ProxyLogData) errorHandleAnalytics(ctx Context, analytics *pb.AnalyticsData) errorHandleBudgetUsage(ctx Context, usage *pb.BudgetUsageData) error
- Exporting proxy logs to external systems
- Sending analytics to data warehouses
- Custom budget tracking
- Real-time monitoring and alerting
examples/plugins/unified/data-collectors/file-analytics-collector/(unified SDK)examples/plugins/unified/data-collectors/file-budget-collector/(unified SDK)examples/plugins/unified/data-collectors/file-proxy-collector/(unified SDK)examples/plugins/gateway/elasticsearch_collector/
6. CustomEndpointHandler
Interface:CustomEndpointHandler
Methods:
GetEndpointRegistrations() ([]*pb.EndpointRegistration, error)HandleEndpointRequest(ctx Context, req *pb.EndpointRequest) (*pb.EndpointResponse, error)HandleEndpointRequestStream(ctx Context, req *pb.EndpointRequest, stream grpc.ServerStreamingServer[pb.EndpointResponseChunk]) error
/plugins/{slug}/. Plugins have full control over the response. Use for:
- Custom APIs (OAuth endpoints, webhooks, health checks)
- MCP Streamable HTTP proxy servers
- Protocol-specific proxies
- Any endpoint that doesn’t fit the LLM/Tool/Datasource model
stream_response flag on endpoint registrations.
Full Guide: Custom Endpoints Guide
Quick Start
1. Project Setup
2. Implement Plugin Structure
Use the unified SDK withBasePlugin convenience struct:
Expandable
3. Implement Capability Interfaces
Implement one or more capability interfaces based on your needs:PostAuthHandler (Most Common)
Expandable
PreAuthHandler
Expandable
ResponseHandler
Expandable
DataCollector
Expandable
4. Build Plugin
5. Deploy Plugin
Create plugin in AI Studio dashboard or via API:6. Attach to LLM
Associate the plugin with an LLM to activate it:Configuration Schema
Provide JSON Schema for plugin configuration using theConfigSchemaProvider interface:
config.schema.json:
Expandable
Initialize() and can be updated via the API.
Complete Examples
Example 1: Custom Authentication Plugin
This example uses the Unified SDK for consistency with other gateway plugins likellm-firewall and llm-cache.
Expandable
community/plugins/llm-firewall/ for a production-ready content filtering plugin using this pattern.
Example 2: Elasticsearch Data Collector
Expandable
Plugin Context
ThePluginContext provides contextual information about the request:
Testing Your Plugin
Unit Testing
Expandable
Integration Testing
Usefile:// deployment to test with real LLM requests:
Expandable
Best Practices
Performance
- Keep plugin logic lightweight and fast
- Use timeouts for external API calls
- Implement connection pooling for external services
- Cache frequently accessed data
- Return early for requests that don’t need processing
Error Handling
- Log errors with context (request ID, LLM ID, etc.)
- Return descriptive error messages
- Don’t panic - return errors properly
- Implement graceful degradation
Security
- Validate all configuration inputs
- Sanitize user-provided data
- Use secure connections for external services
- Don’t log sensitive data (tokens, PII)
- Implement rate limiting for external calls
Configuration
- Provide sensible defaults
- Use JSON Schema for validation
- Document all configuration options
- Support configuration updates without restart
Troubleshooting
Plugin Not Loading
Plugin Not Loading
- Check plugin command path is absolute with
file:// - Verify plugin binary has execute permissions
- Check logs for initialization errors
- Ensure plugin implements all required interfaces
Plugin Crashes
Plugin Crashes
- Check plugin logs for panics
- Verify external service connectivity
- Test with minimal configuration
- Use defensive error handling
Performance Issues
Performance Issues
- Profile plugin with Go profiler
- Check for blocking operations
- Monitor external service latency
- Review resource usage (CPU, memory)
Gateway Services
Gateway plugins have access to Gateway-specific services viactx.Services.Gateway():
Sending Data to Control Plane
Gateway plugins can send data back to AI Studio (the control plane) using theSendToControl API. This is useful for:
- Aggregating statistics from edge instances
- Synchronizing state across the hub-and-spoke architecture
- Sending alerts or notifications to central plugins
Expandable
EdgePayloadReceiver interface.
See Edge-to-Control Communication for complete documentation.
Working with Both Runtimes
Plugins using the unified SDK can work in both Gateway and Studio:Expandable