Docs menu

Cookbook

Cookbook

Runnable recipes in curl, Python and TypeScript for the ten Dex use cases, each with the answer the live API gave, plus patterns for routing, agent gates, batches, retries, version pins and cost.

View as Markdown

Each recipe is a complete program you can run with a free test key. The use-case recipes show the request, the same call in curl, Python and TypeScript, the response the live API returned for it, and the code that acts on the answer. The patterns show how to build Dex into a larger system.

Use cases

Recipe Questions What your code does with the answer
Route and prioritise support tickets pick, rate, check Routes the ticket to a team, raises the priority, flags churn risk
Moderate marketplace posts pick, rate, check Removes clear scams, queues the rest for reviewers
Score inbound leads pick, rate, check Fills CRM fields and books a call
Gate an agent's tool call pick, check, check Runs, confirms or blocks the call
Triage documents and email pick, pick, check, rate Files the email with the right department
Categorise product listings pick, check, pick Sets the category and condition, holds prohibited items
Read sentiment and stance rate, pick, check Feeds a dashboard, alerts on price complaints
Check messages against a policy check, check, pick, rate Stops a message before it is sent
Grade LLM outputs check, check, check, rate Scores an eval run on a pinned version
Check data quality check, pick, check Merges duplicates, fixes field types

Patterns

How the recipes were made

  • Every request file validates against the API contract, and a test in our build checks each response against its request: answers in question order, probabilities that sum to 1, the choice with the highest probability, and abstained exactly when the confidence is below min_confidence.
  • The responses were captured from https://api.thinqit.ai with a test key. They name the model version that answered. On that exact version the same request always returns the same answers, so you get the output shown when you send the same request.
  • The requests use the alias dex-1 unless they pin a version. When the alias moves to a newer version, your answers can differ slightly from the ones shown. Pin the version named in the response to reproduce them exactly (see Determinism).

Before you run them

  1. Create a test key in the console and put it in DEX_API_KEY. Test keys are free up to 250,000 tokens a day per account; every recipe uses a few hundred.
  2. Install the SDKs from Downloads (Python 3.10 or newer, Node 18 or newer).
  3. Save Python code as a .py file and run it with python. Save TypeScript code as a .mts file and run it with npx tsx, for example npx tsx support-routing.mts: the samples use await at the top level, which needs an ES module, and the .mts ending makes the file one whatever your package.json says.

To implement one of these recipes with an AI coding assistant, give it the rules on Implement Dex with an AI assistant.