Errors
A failed call returns a code. SDKs throw that code. HTTP returns it in the JSON body. The message never includes your API key.
| Code | When |
|---|---|
invalid_api_key | The key is missing or not recognized. |
unauthorized | The key cannot call this decision. |
invalid_request | The body is not a decide request. |
invalid_decision | The decision name is missing or empty. |
invalid_options | Options are missing, empty, or have no id. |
rate_limited | Too many calls in a short window. |
unavailable | The Owctopus API could not be reached. |
decision_unavailable | A decision could not be produced for this request. |
timeout | The call exceeded the client timeout. |
In your backend
import { OwctopusError } from "@owctopus/sdk";
try {
const result = await owctopus.decide({
decision: "meal_suggestion",
context: { caloriesSoFar: 980, hunger: "high" },
options: [
{ id: "chicken_bowl", calories: 540 },
{ id: "salad", calories: 320 },
],
});
} catch (error) {
if (error instanceof OwctopusError) {
console.error(error.code);
}
}Timeouts and unavailable responses can be retried. Invalid keys, invalid options, and unauthorized calls should be fixed before you retry. Context can be any object your app needs. Options still need an id on every item, because that id is what comes back as the decision.