Skip to main content

AI/ML API

AI/ML API hosts models from OpenAI, Anthropic, Google, Meta, and other providers behind an OpenAI-compatible API.

OpenAI Compatibility​

Promptfoo uses the OpenAI provider request format. Supported parameters depend on the model and endpoint.

Setup​

To use AI/ML API, you need to set the AIML_API_KEY environment variable or specify the apiKey in the provider configuration.

Example of setting the environment variable:

export AIML_API_KEY=your_api_key_here

Get your API key at aimlapi.com.

Provider Formats​

Chat Models​

aimlapi:chat:<model_name>

Completion Models​

aimlapi:completion:<model_name>

Embedding Models​

aimlapi:embedding:<model_name>

Shorthand Format​

You can omit the type to default to chat mode:

aimlapi:<model_name>

For Claude 5, set omitDefaults: true to omit Promptfoo's default temperature: 0. Leave sampling parameters unset in your config and environment; explicit values still apply.

Configuration​

Configure the provider in your promptfoo configuration file:

promptfooconfig.yaml
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
providers:
- id: aimlapi:chat:google/gemini-3-5-flash
config:
temperature: 0.7
max_tokens: 2000

Configuration Options​

Common OpenAI parameters include:

ParameterDescription
apiKeyYour AI/ML API key
temperatureControls randomness (0.0 to 2.0)
max_tokensMaximum number of tokens to generate
top_pNucleus sampling parameter
frequency_penaltyPenalizes frequent tokens
presence_penaltyPenalizes new tokens based on presence
stopSequences where the API will stop generating

Promptfoo requests complete responses; this provider does not support streaming.

Use the model ID shown in the AI/ML API catalog, including its publisher prefix. Examples:

Reasoning Models​

Advanced Language Models​

Open Source Models​

Embedding Models​

Example Configurations​

Basic Example​

promptfooconfig.yaml
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
providers:
- aimlapi:chat:deepseek/deepseek-v4-pro
- aimlapi:chat:openai/gpt-5.6-luna
- id: aimlapi:chat:anthropic/claude-sonnet-5
config:
omitDefaults: true

prompts:
- 'Explain {{concept}} in simple terms'

tests:
- vars:
concept: 'quantum computing'
assert:
- type: contains
value: 'qubit'

Advanced Configuration with Multiple Models​

promptfooconfig.yaml
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
providers:
- id: aimlapi:chat:deepseek/deepseek-v4-pro
label: 'DeepSeek V4 Pro'
config:
max_tokens: 4000

- id: aimlapi:chat:openai/gpt-5.6-luna
label: 'GPT-5.6 Luna'

- id: aimlapi:chat:google/gemini-3-5-flash
label: 'Gemini 3.5 Flash'
config:
temperature: 0.5

prompts:
- 'Write Python code to {{task}}. Return only the code, without Markdown fences.'

tests:
- vars:
task: 'implement a binary search tree in Python'
assert:
- type: python
value: |
# Verify the code is valid Python
import ast
try:
ast.parse(output)
return True
except SyntaxError:
return False
- type: llm-rubric
value: 'The code should include insert, search, and delete methods'

Embedding Example​

Embedding models back the similar assertion. Set them under defaultTest.options.provider.embedding; an embedding model cannot be used as a top-level eval provider. Extra request fields such as dimensions go under config.passthrough.

promptfooconfig.yaml
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
providers:
- aimlapi:chat:openai/gpt-5.6-luna

defaultTest:
options:
provider:
embedding:
id: aimlapi:embedding:openai/text-embedding-3-large
config:
passthrough:
dimensions: 1024 # Optional: reduce embedding dimensions

prompts:
- 'Describe {{topic}} in one sentence.'

tests:
- vars:
topic: 'a fox jumping over a dog'
assert:
- type: similar
value: 'The quick brown fox jumps over the lazy dog'
threshold: 0.7

JSON Mode Example​

promptfooconfig.yaml
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
providers:
- id: aimlapi:chat:openai/gpt-5.6-luna
config:
response_format: { type: 'json_object' }

prompts:
- |
Extract the following information from the text and return as JSON:
- name
- age
- occupation

Text: {{text}}

tests:
- vars:
text: 'John Smith is a 35-year-old software engineer'
assert:
- type: is-json
- type: javascript
value: |
const data = JSON.parse(output);
return data.name === 'John Smith' &&
data.age === 35 &&
data.occupation === 'software engineer';

Getting Started​

Test your setup with working examples:

npx promptfoo@latest init --example provider-aiml-api

Notes​

Check AI/ML API pricing for rates and account limits.