SDK & API

Run evaluations from code with the evaluate() function

Evals from code

Everything you can do with evals in the platform, you can also do from code. The ai-evaluation package gives you a single evaluate() function that runs a metric locally, in the cloud, or as an LLM judge, and returns a result you can assert on.

This page is the reference for reaching evals programmatically. For the full SDK docs, see the SDK evals section.

Install and authenticate

pip install ai-evaluation
from fi.evals import evaluate

The 76+ local metrics run without an API key. Cloud evals and LLM-as-Judge need your Future AGI credentials:

export FI_API_KEY="your-api-key"
export FI_SECRET_KEY="your-secret-key"

Find both under Settings → API Keys in the platform.

The LLM-as-Judge engine doesn’t use these keys: it goes through LiteLLM, which reads your model provider’s standard environment variable (OPENAI_API_KEY, GEMINI_API_KEY, and so on).

One function, three engines

evaluate() picks the engine from what you pass. You never call a different function to switch engines.

You passEngineSpeedKey needed
Metric name onlyLocal heuristicunder 1msNo
Metric + model="turing_flash"Cloud (Turing)~1–3sFI_API_KEY + FI_SECRET_KEY
prompt= + engine="llm" + model=LLM-as-Judge~2–5sModel provider key

Force an engine with engine="local", engine="turing", or engine="llm".

There’s also a combined mode: a metric plus model= and augment=True runs the local heuristic first, then hands its score and reasoning to the LLM for refinement.

# Local metric: instant, no key
result = evaluate("contains", output="Hello world", keyword="Hello")

# Cloud metric: needs credentials + model
result = evaluate("toxicity", output="You're doing great!", model="turing_flash")

# LLM-as-Judge: custom criteria
result = evaluate(
    prompt="Rate helpfulness from 0 to 1",
    output="Here are 3 steps to fix that...",
    engine="llm",
    model="gemini/gemini-2.5-flash",
)

The Turing engine calls the same evaluation API the platform uses, so a template scored from code returns the same score you’d see in the platform.

What a result contains

A single eval returns an EvalResult. A list of metrics returns one result per metric.

FieldDescription
eval_nameThe metric that produced this result
scoreThe numeric result: 1.0 / 0.0 for pass/fail metrics, or a 01 value
passedThe boolean verdict
reasonWhy the evaluator scored it that way
latency_msHow long the eval took
status”completed”, or “error” when the run failed
errorThe error message when status is “error”
metadataExtra engine-specific detail about the run

When a metric returns only a score, passed derives from score >= 0.5.

print(result.score)    # 1.0
print(result.passed)   # True
print(result.reason)   # "Keyword 'Hello' found"
# Batch: several metrics in one call
results = evaluate(["contains", "is_json"], output='{"greeting": "Hello"}', keyword="Hello")
for r in results:
    print(r.eval_name, r.passed)

Warning

Don’t mix local and cloud metrics in one batch call. If you pass model="turing_flash", local metrics return score=None. Run them in separate calls.

Function signature

def evaluate(
    eval_name: str | list[str] | None = None,
    *,
    prompt: str | None = None,
    engine: str | None = None,
    model: str | None = None,
    augment: bool | None = None,
    config: dict | None = None,
    feedback_store: Any | None = None,
    generate_prompt: bool = False,
    fi_api_key: str | None = None,
    fi_secret_key: str | None = None,
    fi_base_url: str | None = None,
    **inputs,
) -> EvalResult | BatchResult

Inputs the metric needs (output, context, expected_response, and so on) are passed as keyword arguments. The Built-in evals reference lists the required inputs for each template.

generate_prompt=True turns a short plain-English prompt into full grading criteria before the run; it needs a model=.

Keep exploring

The SDK reference in depth:

PageWhat it covers
evaluate()The full evaluate() reference: parameters, return types, batch runs
Metrics ReferenceEvery local metric by category: string, JSON, similarity, hallucination, RAG, agents, guardrails
Cloud Evals100+ pre-built Turing templates
LLM-as-JudgeCustom criteria with any LiteLLM model
StreamingScore output token-by-token with early stopping
Distributed EvaluatorRun at scale with ThreadPool, Celery, Ray, or Temporal
Was this page helpful?

Questions & Discussion