> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokz.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Answer typed decisions about texts

> Asks one or more typed questions (choice, multilabel, bool, score) about up to 64 texts and returns, per text and question, the best option, the selected options, a probability distribution over the options, and for scores the expected value. This runs an OpenDecision model: the text is sent to a Tokz-run model service. It is not stored or logged; only counters are kept. Billed per token at the price of the chosen model, from the prepaid credit balance, and only when the request succeeds. Give the name of a fine tune your organization owns as model and leave out decisions to run that model on the API server's own CPU, up to 16 texts per request. The answer is then under the key decision.



## OpenAPI

````yaml /openapi.json post /decide
openapi: 3.1.0
info:
  title: tokz API
  version: 1.0.0
  description: >-
    Typed decisions about text from the open OpenDecision models. Text sent to
    /decide is read by the model and never stored or logged; only counters are
    kept. Fine tunes are built in the dashboard, which is not part of this API.
  contact:
    name: tokz
    url: https://tokz.dev
servers:
  - url: https://api.tokz.dev
    description: Production
  - url: http://127.0.0.1:3999
    description: Local dev (dev:pglite)
security:
  - bearerAuth: []
tags:
  - name: Decisions
    description: Typed decisions about text, answered by the OpenDecision models.
  - name: Fine tunes
    description: >-
      The files of a model you trained. Starting, canceling and deleting one
      happen in the dashboard.
  - name: Operations
    description: Health and diagnostics.
paths:
  /decide:
    post:
      tags:
        - Decisions
      summary: Answer typed decisions about texts
      description: >-
        Asks one or more typed questions (choice, multilabel, bool, score) about
        up to 64 texts and returns, per text and question, the best option, the
        selected options, a probability distribution over the options, and for
        scores the expected value. This runs an OpenDecision model: the text is
        sent to a Tokz-run model service. It is not stored or logged; only
        counters are kept. Billed per token at the price of the chosen model,
        from the prepaid credit balance, and only when the request succeeds.
        Give the name of a fine tune your organization owns as model and leave
        out decisions to run that model on the API server's own CPU, up to 16
        texts per request. The answer is then under the key decision.
      operationId: decide
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DecideRequest'
            examples:
              supportTicket:
                summary: Route a support ticket and flag urgency
                value:
                  inputs: >-
                    I was charged twice for my May invoice and the app keeps
                    logging me out.
                  decisions:
                    queue:
                      type: choice
                      question: Which team should handle this ticket?
                      options:
                        - billing
                        - technical
                        - account
                        - sales
                    urgent:
                      type: bool
              fineTune:
                summary: Call a fine tune by name
                value:
                  model: support-triage
                  inputs: I was charged twice for my May invoice.
      responses:
        '200':
          description: >-
            One object per input, keyed by decision name. A fine tune uses the
            fixed key decision.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DecideResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/InsufficientCredits'
        '413':
          description: >-
            The request body exceeds 4 MiB, or (input_too_large) a text needs
            more memory than a hosted fine tune with this many labels allows.
            Nothing was charged.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: >-
            Too many requests for this API key, or (decide_org_busy) too many
            texts in progress on hosted fine tunes for this organization.
            Nothing was charged.
          headers:
            Retry-After:
              description: >-
                Seconds to wait before sending again. Present on most refusals
                of a fine tune.
              schema:
                type: integer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '502':
          description: The model service did not answer. Nothing was charged; retry.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: >-
            The model service or hosted fine tunes are busy (decide_busy), a
            fine tune is loading or cannot load (model_unavailable), Fine Tune
            is off (fine_tune_off), or the model service is not available on
            this deployment (decide_unavailable). Nothing was charged.
          headers:
            Retry-After:
              description: >-
                Seconds to wait before sending again. Present on most refusals
                of a fine tune.
              schema:
                type: integer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    DecideRequest:
      type: object
      required:
        - inputs
      additionalProperties: false
      properties:
        model:
          type: string
          description: >-
            A catalog model (opendecision-small, opendecision-large-packed,
            opendecision-large), or the name of a fine tune your organization
            owns.
          default: opendecision-large-packed
        inputs:
          oneOf:
            - type: string
              minLength: 1
              maxLength: 20000
            - type: array
              minItems: 1
              maxItems: 64
              items:
                type: string
                minLength: 1
                maxLength: 20000
          description: >-
            One text or up to 64, each at most 20,000 characters. A fine tune
            takes up to 16.
        decisions:
          type: object
          minProperties: 1
          maxProperties: 16
          additionalProperties:
            $ref: '#/components/schemas/DecideDecision'
          description: >-
            Questions keyed by name, 1 to 16 per request. Required for a catalog
            model, and refused for a fine tune, which already knows its question
            and labels.
    DecideResponse:
      type: object
      required:
        - id
        - model
        - results
        - usage
      properties:
        id:
          type: string
        model:
          type: string
        results:
          type: array
          items:
            type: object
            additionalProperties:
              $ref: '#/components/schemas/DecideResult'
          description: >-
            One object per input, in order, keyed by decision name. A fine tune
            uses the fixed key decision.
        usage:
          type: object
          required:
            - billed_tokens
            - cost_usd
          properties:
            billed_tokens:
              type: integer
            cost_usd:
              type: number
              description: billed_tokens at the model's list price.
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: A code or a short message. Never contains payload content.
        message:
          type: string
          description: >-
            What went wrong and what to do next, when the API has a sentence for
            it.
        requestId:
          type: string
    DecideDecision:
      type: object
      required:
        - type
      additionalProperties: false
      description: >-
        One question. choice and multilabel need options (2 to 256, unique ids);
        bool and score take none.
      properties:
        type:
          type: string
          enum:
            - choice
            - multilabel
            - bool
            - score
        question:
          type: string
          maxLength: 1000
        options:
          type: array
          minItems: 2
          maxItems: 256
          items:
            $ref: '#/components/schemas/DecideOption'
        threshold:
          type: number
          exclusiveMinimum: 0
          exclusiveMaximum: 1
          default: 0.5
          description: >-
            multilabel only: an option is selected when its probability reaches
            this.
        low:
          type: integer
          default: 0
          description: score only.
        high:
          type: integer
          default: 5
          description: score only.
        step:
          type: integer
          minimum: 1
          default: 1
          description: score only. The range must hold 2 to 256 values.
    DecideResult:
      type: object
      required:
        - type
        - best
        - selected
        - policy
        - value
      properties:
        type:
          type: string
          enum:
            - choice
            - multilabel
            - bool
            - score
        best:
          type: string
          description: The highest-probability option.
        selected:
          type: array
          items:
            type: string
          description: >-
            multilabel: every option whose value reaches the threshold.
            Otherwise the best option.
        policy:
          type: object
          additionalProperties:
            type: number
          description: Distribution over the options; sums to 1.
        value:
          type: object
          additionalProperties:
            type: number
          description: Per-option probability that the option is correct.
        score:
          type:
            - number
            - 'null'
          description: 'score only: the expected value.'
    DecideOption:
      oneOf:
        - type: string
          minLength: 1
          maxLength: 500
        - type: object
          required:
            - id
          additionalProperties: false
          properties:
            id:
              type: string
              minLength: 1
              maxLength: 200
            name:
              type:
                - string
                - 'null'
              maxLength: 500
            description:
              type:
                - string
                - 'null'
              maxLength: 2000
  responses:
    BadRequest:
      description: The request body is malformed or a field is out of range.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Missing, malformed, revoked, or incorrect API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InsufficientCredits:
      description: >-
        The account behind the key has no remaining prepaid credits. Add credits
        and retry; the request was not processed.
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                type: string
                enum:
                  - insufficient_credits
              balance:
                type: integer
                description: Remaining balance in cents (0 when exhausted).
            required:
              - error
              - balance
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Your API key: `Authorization: Bearer tokz_live_<id>_<secret>`. Only a
        SHA-256 hash of the secret is stored.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.