Changing a prompt is easy. Knowing whether the new prompt is actually better is the hard part.
This example builds a small prompt A/B testing API on Telnyx Edge Compute. You send one task and two prompt variants. The app runs both variants through Telnyx AI Inference, stores the experiment in a Stateful Actor, and lets users vote on which result they prefer.
Code: https://github.com/team-telnyx/telnyx-code-examples/tree/main/edge-prompt-ab-tester
What it does
The app gives you a tiny evaluation loop:
- create an experiment
- compare two model responses
- vote for variant A or B
- close the experiment
- check aggregate stats
Routes:
POST /experimentsPOST /experiments/<id>/votePOST /experiments/<id>/closeGET /experimentsGET /experiments/<id>GET /statsGET /health/livenessGET /health/readiness
Create a prompt experiment
curl -X POST https://edge-prompt-ab-tester-<id>.telnyxcompute.com/experiments \
-H "Content-Type: application/json" \
-d '{
"task": "Write a one-sentence tagline for an edge compute platform.",
"variant_a": "You are a concise marketing copywriter. Return just the tagline.",
"variant_b": "You are a technical explainer. Return just the tagline, focus on latency."
}'
Response:
{
"id": "exp-msf712rs-0",
"task": "Write a one-sentence tagline for an edge compute platform.",
"variant_a": {
"prompt": "You are a concise marketing copywriter. Return just the tagline.",
"response": "Real-time compute, right where your data lives."
},
"variant_b": {
"prompt": "You are a technical explainer. Return just the tagline, focus on latency.",
"response": "Execute code milliseconds from your users to eliminate network latency."
},
"votes_a": 0,
"votes_b": 0,
"status": "open",
"created_at": "2026-08-04T21:51:55Z"
}
Vote on a result
curl -X POST https://edge-prompt-ab-tester-<id>.telnyxcompute.com/experiments/exp-msf712rs-0/vote \
-H "Content-Type: application/json" \
-d '{"variant":"a"}'
Close the experiment:
curl -X POST https://edge-prompt-ab-tester-<id>.telnyxcompute.com/experiments/exp-msf712rs-0/close
Check stats:
curl https://edge-prompt-ab-tester-<id>.telnyxcompute.com/stats
Example:
{
"total_experiments": 3,
"open_experiments": 2,
"closed_experiments": 1,
"total_votes": 15,
"leader": "variant_a",
"leader_votes": 9
}
The AI call
The app uses:
POST /v2/ai/chat/completions
Default model:
zai-org/GLM-5.2
Each prompt variant becomes the system message. The task becomes the user message. Both variants run against the same input, which makes the comparison easier to reason about.
Why Stateful Actors?
Prompt tests need a little bit of memory.
This example uses an ABTester Stateful Actor to store:
- experiments
- prompt variants
- model responses
- vote counts
- open or closed status
- aggregate stats
That means the API can remember experiment state without adding a separate database just for the demo.
Run it
git clone https://github.com/team-telnyx/telnyx-code-examples.git
cd telnyx-code-examples/edge-prompt-ab-tester
Store your API key as an Edge Compute secret:
telnyx-edge auth api-key set <YOUR_API_KEY>
telnyx-edge secrets add TELNYX_API_KEY "KEY0123..."
Install and deploy:
npm install
telnyx-edge ship
Then use the deployed URL to create experiments and collect votes.
Production notes
Before using this pattern for real product decisions, I would add:
- authentication
- evaluator identity
- duplicate vote prevention
- randomized or blinded variants
- fixed evaluation sets
- scoring rubrics
- prompt version history
- privacy controls for sensitive tasks
But even in this small form, it is useful. Prompt changes should not be judged only by vibes. They should leave a trail of examples, votes, and outcomes.
Resources:
- Code: https://github.com/team-telnyx/telnyx-code-examples/tree/main/edge-prompt-ab-tester
- Telnyx Edge Compute docs: https://developers.telnyx.com/docs/edge-compute
- Telnyx AI Inference docs: https://developers.telnyx.com/docs/inference
- Telnyx AI skills and toolkits: https://github.com/team-telnyx/ai
- Telnyx Portal: https://portal.telnyx.com/
Top comments (0)