Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

OpenAI Decisions API: Predicate Choice & Score

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The OpenAI Decisions API (part of the Responses API) lets you evaluate a piece of text against a set of custom criteria you define as predicates. Each predicate is a natural-language statement (like "the email is spam" or "the tone is professional"), and the API returns a score (0 to 1) indicating how strongly the text matches that predicate. You can also set a threshold to get a boolean true/false result. This is useful for content moderation, sentiment checks, or any classification task where you want to avoid writing complex regex or fine-tuning a model.

What You'll Need

  • An OpenAI API key (sign up at platform.openai.com, add billing, and create a key).
  • Basic familiarity with making HTTP requests (curl, Python, or any language).
  • Access to a model that supports the Decisions API — currently gpt-4.1 or gpt-4.1-mini (check OpenAI's current docs for the latest list).

Step-by-Step

  1. Understand the input structure. The Decisions API is called via the Responses API endpoint: POST https://api.openai.com/v1/responses. You send a model, a text (the content to evaluate), and a decisions array containing your predicates.
  2. Define your predicates. Each predicate is an object with two fields: name (a short label, e.g., "spam") and expression (a natural-language statement, e.g., "The text is unsolicited promotional content"). You can have multiple predicates in one call.
  3. Set a threshold (optional). Add a threshold field (a float between 0 and 1) to each predicate to get a result of true or false based on whether the score meets or exceeds that threshold. If you omit the threshold, you only get the raw score.
  4. Make the API call. Here's a minimal curl example (replace YOUR_API_KEY):
    curl https://api.openai.com/v1/responses \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -d '{"model": "gpt-4.1", "text": "Buy now! Limited offer!", "decisions": [{"name": "spam", "expression": "The text is promotional and unsolicited", "threshold": 0.7}]}'
  5. Parse the response. The response will contain a decisions array. Each item has name, score (0–1), and result (if threshold was set). For the example above, you might get score: 0.95 and result: true.
  6. Use the results in your application. For each predicate, read the score to get a confidence level, or read result for a simple yes/no. You can then trigger actions (e.g., flag an email, block a comment).
  7. Test with multiple predicates. You can send up to 10 predicates in one call. For example, to classify customer feedback, you might define predicates for "positive", "negative", and "urgent". The API will score each independently.

Common Mistakes

  • Writing vague expressions. "The text is good" is ambiguous. Be specific: "The text expresses satisfaction with a product or service".
  • Forgetting the threshold. If you need a boolean, you must set a threshold; otherwise you only get a score and have to interpret it yourself.
  • Using an unsupported model. The Decisions API is not available on older models like gpt-3.5-turbo. Check the official docs for the current supported list.
  • Ignoring the score distribution. A score of 0.6 might be "high" for some expressions but low for others. Test with real data to calibrate your thresholds.
  • Assuming the API is a classifier. It's a text evaluator, not a trained classifier. It uses the model's language understanding, so results can vary with phrasing.

Tips

  • Start with a low threshold (e.g., 0.5) and adjust based on your precision/recall needs.
  • Use negative examples in your expression: "The text is not a question" can be more effective than "The text is a statement".
  • Combine multiple predicates to get richer insights in one call, saving latency and cost.
  • If you need to evaluate long documents, consider splitting them into chunks and averaging scores, as very long inputs may dilute the signal.
  • Keep a small test set of labeled examples to tune your thresholds before going live.
  • Remember that the API is stateless — each call is independent. If you need to track history, store results on your side.

Troubleshooting

  • Error: "model does not support decisions" — You're using a model that doesn't support the Decisions API. Switch to gpt-4.1 or gpt-4.1-mini (check the latest docs).
  • Error: "invalid expression" — Your expression is empty or malformed. Make sure it's a non-empty string.
  • Score is always 0 or 1 — The expression might be too absolute. Rephrase to allow nuance, e.g., "The text is likely to be spam" instead of "The text is spam".
  • Result is always true/false — Your threshold is too low or too high. Adjust it based on a sample of scores you get without a threshold.
  • Latency is high — The Decisions API can be slower than a simple chat call. If you're making many calls, batch predicates into one request.
  • Rate limit errors — You're hitting your API rate limit. Implement exponential backoff or increase your quota.

Frequently Asked Questions

Can I use the Decisions API with any OpenAI model?

No. It's only available on specific models like gpt-4.1 and gpt-4.1-mini. Check the official documentation for the current list.

What's the difference between score and result?

Score is a float from 0 to 1 representing the model's confidence that the text matches the predicate. Result is a boolean that appears only if you set a threshold — it's true if score ≥ threshold, else false.

Can I use multiple predicates in one call?

Yes, up to 10 predicates per request. Each is evaluated independently, and you get a separate score/result for each.

Is the Decisions API free?

No, it's billed like any other API call based on token usage. The cost depends on the model and the length of the text and expressions.

Can I use the Decisions API for real-time moderation?

Yes, but keep in mind the latency (typically a few seconds). For high-volume real-time use, you might want to use a dedicated moderation model or fine-tune a smaller model.

How do I choose a good threshold?

Run a sample of texts through the API without a threshold, collect the scores, and then pick a threshold that separates positive and negative examples based on your tolerance for false positives/negatives.