Guides
Examples
Common usage patterns for PromptDiff.
Choosing the cheapest model
Compare models and programmatically select the cheapest one that meets a quality threshold.
python
import promptdiff
client = promptdiff.Client(api_key="pd_...")
result = client.compare(
prompt="Classify this text as spam or not: {input}",
models=["gpt-4o-mini", "claude-3-haiku", "gemini-1.5-flash"],
input="Congratulations! You have won a prize."
)
# Sort by cost
by_cost = sorted(result.results, key=lambda r: r.cost_usd)
cheapest = by_cost[0]
print("Cheapest:", cheapest.model, "cost:", cheapest.cost_usd)Latency benchmarking
bash
curl -X POST https://promptdiff.bizmarq.com/api/v1/compare \
-H "Authorization: Bearer pd_your_key" \
-d '{
"prompt": "Respond with exactly one word: yes",
"models": ["gpt-4o-mini", "claude-3-haiku", "gemini-1.5-flash"],
"options": { "max_tokens": 5 }
}'JavaScript / TypeScript
compare.ts
const response = await fetch(
"https://promptdiff.bizmarq.com/api/v1/compare",
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.PROMPTDIFF_API_KEY}`,
},
body: JSON.stringify({
prompt: "Explain closures in JavaScript briefly.",
models: ["gpt-4o-mini", "claude-3-haiku"],
options: { temperature: 0.5, max_tokens: 200 },
}),
}
);
const data = await response.json();
console.log(`Fastest: ${data.meta.fastest_model}`);
console.log(`Total cost: $${data.meta.total_cost_usd}`);