Decide

POST /v1/organisations/{organisation_id}/spaces/{space_id}/apps/{app_id}/instances/{instance_id}/decisions

Asks TypeSafe AI's Jev the instance's questions about a state, all in one call: yes or no, one of several options, or a place on a scale, each answer with its probability and, where Jev gives one, its confidence, so the app acts on confident answers and hands the rest on.

Only the instance's own app token asks (the TypeSafe AI space's app offers it to agents as tools). The call runs on the installation's TypeSafe AI account and is billed in credits as a model call of the app's principal (source decision), within the plan's limits. The state and questions are never logged.

Authentication

Send an API key, or an access token from your organisation’s identity provider, in the Authorization header. How API keys work

Scope the API key needs: conversations:write

Security schemes in the OpenAPI document: session_cookie (cookie __Host-ivy_session)bearer (bearer)api_key (bearer)

Parameters

  • organisation_id path string required
  • space_id path string required
  • app_id path string required
  • instance_id path string required

Request body

application/json DecisionRequest required

  • questions Question[] required

    1 to 16 questions, answered together against the same state.

  • state string required

    What the questions are about: a message, a document, a situation.

Responses

  • 200 application/json Decisions

    An answer to each question, in the request's order

  • 401 application/json ErrorBody

    unauthenticated

  • 402 application/json ErrorBody

    usage_limit_reached, billing_restricted, service_identity_limit_reached

  • 403 application/json ErrorBody

    insufficient_scope: only an app instance asks, with its own app token; viewers can't use a write app. eu_only_processing: the organisation allows only EU processing, and TypeSafe AI has no EU route. access_revoked: the app's principal lost access, or the space was archived, before the decision ran

  • 404 application/json ErrorBody

    Not the token's organisation or space

  • 422 application/json ErrorBody

    validation_failed with the field and reason (required, too_long, out_of_range, duplicate, invalid_format, not_allowed); invalid_body

  • 429 application/json ErrorBody

    rate_limited: the instance's requests per minute

  • 500 application/json ErrorBody

    internal

  • 502 application/json ErrorBody

    decision_refused: TypeSafe AI refused the questions

  • 503 application/json ErrorBody

    provider_unavailable: this installation has no TypeSafe AI account, or it didn't answer in time; or unavailable: the database is briefly unavailable; retry after Retry-After seconds

Error codes

Errors come back as an ErrorBody whose code is one of these.

  • 401 unauthenticated
  • 402 usage_limit_reachedbilling_restrictedservice_identity_limit_reached
  • 403 insufficient_scope
  • 404 not_found generic code for this status
  • 422 validation_failedtoo_longout_of_rangeduplicateinvalid_formatnot_allowedinvalid_body
  • 429 rate_limited
  • 500 internal
  • 502 decision_refused
  • 503 provider_unavailableunavailable

Examples

curl
curl -X POST "$IVY_API_URL/v1/organisations/$ORGANISATION_ID/spaces/$SPACE_ID/apps/$APP_ID/instances/$INSTANCE_ID/decisions" \
  -H "Authorization: Bearer $IVY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "questions": [
      {
        "id": "id_123",
        "kind": "boolean",
        "options": [
          {
            "description": "string",
            "name": "Ada Lovelace"
          }
        ],
        "prompt": "string",
        "scale": [
          "string"
        ]
      }
    ],
    "state": "string"
  }'
JavaScript SDK
import { client, decide } from "@spacivapp/ivy-sdk";

client.setConfig({
  baseUrl: process.env.IVY_API_URL,
  headers: { Authorization: `Bearer ${process.env.IVY_API_KEY}` },
});

const { data, error, response } = await decide({
  path: { organisation_id: organisationId, space_id: spaceId, app_id: appId, instance_id: instanceId },
  body: {
    questions: [
      {
        id: "id_123",
        kind: "boolean",
        options: [
          {
            description: "string",
            name: "Ada Lovelace"
          }
        ],
        prompt: "string",
        scale: [
          "string"
        ]
      }
    ],
    state: "string"
  },
});
Example request body
{
  "questions": [
    {
      "id": "id_123",
      "kind": "boolean",
      "options": [
        {
          "description": "string",
          "name": "Ada Lovelace"
        }
      ],
      "prompt": "string",
      "scale": [
        "string"
      ]
    }
  ],
  "state": "string"
}
Example response (200)
{
  "answers": [
    {
      "confidence": 1,
      "id": "id_123",
      "kind": "boolean",
      "probabilities": {},
      "probability": 1,
      "value": false
    }
  ],
  "model": "string"
}