Reference · v0.76.0
Recipes · Cross Model
From the pinned CLI source. Read upstream.
Current format policy: Portable .tine files default to v5 (since 0.42). --for-legacy writes v4. The .tine/ repository format is v3. tine evidence export writes v4.
"""Cross-model comparison — run the same agent on different providers.
Usage:
tine run examples/cross_model.py
Set the API keys for the providers you want to compare.
"""
import os
from opentine import Agent
prompt = "Explain the CAP theorem in distributed systems in exactly 3 sentences."
models = []
if os.environ.get("ANTHROPIC_API_KEY"):
from opentine.models.anthropic import Anthropic
models.append(("anthropic", Anthropic("claude-sonnet-5-5")))
if os.environ.get("OPENAI_API_KEY"):
from opentine.models.openai import OpenAI
models.append(("openai", OpenAI("gpt-6.1-sol")))
if os.environ.get("GOOGLE_API_KEY"):
from opentine.models.google import Google
models.append(("google", Google("gemini-3.8-flash")))
if os.environ.get("OLLAMA_HOST"):
try:
from opentine.models.ollama import Ollama
models.append(("ollama", Ollama("llama3.1")))
except Exception:
pass
if not models:
print("Set a provider API key or OLLAMA_HOST to run this example")
exit(1)
for name, model in models:
print(f"\n--- {name} ({model.name}) ---")
try:
agent = Agent(model=model)
run = agent.run_sync(prompt)
run.save(f"cross_{name}.tine")
last_step = run.steps[-1] if run.steps else None
if last_step:
print(last_step.inputs.get("text", "")[:200])
print(f" Steps: {len(run.steps)}, Cost: ${run.total_cost:.4f}")
except Exception as e:
print(f" Error: {e}")