Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Promptfoo Promptfoo loadApiProvider

From Leeroopedia
Knowledge Sources
Domains Provider_Management, Evaluation
Last Updated 2026-02-14 08:00 GMT

Overview

Concrete tool for resolving provider identifier strings into instantiated ApiProvider objects, provided by the Promptfoo framework.

Description

The loadApiProvider function is the single entry point for provider instantiation. It accepts a provider path string and optional context, then routes through cloud providers, file-based configs, and a registry of 70+ built-in provider factories to create the appropriate ApiProvider instance.

Usage

Import this function when you need to instantiate a provider from a config string. This is used internally by the evaluation pipeline and can also be called directly for custom integrations.

Code Reference

Source Location

  • Repository: promptfoo
  • File: src/providers/index.ts
  • Lines: L31-177

Signature

export async function loadApiProvider(
  providerPath: string,
  context: LoadApiProviderContext = {},
): Promise<ApiProvider>

Import

import { loadApiProvider } from './providers';

I/O Contract

Inputs

Name Type Required Description
providerPath string Yes Provider identifier (e.g., 'openai:gpt-4', 'file://provider.yaml', 'python:my_provider.py')
context LoadApiProviderContext No Loading context with options, basePath, and env overrides

Outputs

Name Type Description
(return) ApiProvider Instantiated provider with callApi(), id(), and optional embedding/classification methods

Usage Examples

Load OpenAI Provider

import { loadApiProvider } from './providers';

const provider = await loadApiProvider('openai:gpt-4o', {
  options: {
    config: { temperature: 0.7 },
  },
  env: { OPENAI_API_KEY: process.env.OPENAI_API_KEY },
});

const result = await provider.callApi('What is 2+2?');
console.log(result.output);

Load Python Custom Provider

const provider = await loadApiProvider('python:my_evaluator.py', {
  basePath: '/path/to/project',
});

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment