Principle:Promptfoo Promptfoo Provider Interface
| Knowledge Sources | |
|---|---|
| Domains | Provider_Management, API_Design |
| Last Updated | 2026-02-14 08:00 GMT |
Overview
A polymorphic interface contract that all LLM providers must implement for uniform evaluation across heterogeneous AI services.
Description
The Provider Interface defines the contract that any LLM integration must fulfill to participate in Promptfoo evaluations. At its core, every provider must implement `id()` (returning a unique identifier) and `callApi()` (sending a prompt and returning a response).
This abstraction layer is what enables Promptfoo to evaluate 70+ providers uniformly: whether the provider is OpenAI, a local Ollama instance, a custom Python script, or an HTTP endpoint, the evaluation engine interacts with them all through the same interface.
Optional methods extend the interface for embedding APIs, classification APIs, session management, and resource cleanup.
Usage
Use this principle when creating custom providers for Promptfoo. Any JavaScript/TypeScript module, Python script, or HTTP endpoint that conforms to this interface can be used as a provider.
Theoretical Basis
Interface Contract:
ApiProvider:
REQUIRED:
id() → string // Unique provider identifier
callApi(prompt, context, options) → ProviderResponse // Main API call
OPTIONAL:
callEmbeddingApi(input) → ProviderEmbeddingResponse
callClassificationApi(prompt) → ProviderClassificationResponse
getSessionId() → string // For multi-turn conversations
cleanup() → void // Resource cleanup on abort
transform: string // Output transformation expression
delay: number // Delay between calls (ms)