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

> ## Agent Instructions
> Krun API base URL: https://api.krun.ai. Authenticate server-side with `Authorization: Bearer $KRUN_API_KEY`; never put a Krun API key in browser code.
> Prefer the Python SDK in examples: `pip install krun-ai`, `from krun import Krun`. The TypeScript SDK `@krun-ai/sdk` is not published on npm yet: do not tell users to `npm install` it.
> The only question type is `choice`. `confidence` is the top-1 minus top-2 probability margin, not the probability that the answer is correct. `choice` is null when `abstain` is true.
> Usage reports `input_tokens` only. There are no output tokens.

# Decide

> Answer one or more `choice` questions about a context in a single call. Each question returns the selected option (or `null` when the model abstains), a probability per option, a confidence margin and an abstention status. The request id is returned in the `X-Request-ID` response header.



## OpenAPI

````yaml https://api.krun.ai/openapi.json post /v1/decide
openapi: 3.1.0
info:
  title: Krun API
  description: >-
    Krun decision API. Authenticate with `Authorization: Bearer krun_live_...`
    from your server.
  version: 1.0.0-beta
servers:
  - url: https://api.krun.ai
    description: Production
security: []
tags:
  - name: decisions
    description: Pick one option for a context
  - name: feedback
    description: Report whether a decision was correct
  - name: models
    description: Available models
  - name: health
    description: Liveness and readiness
paths:
  /v1/decide:
    post:
      tags:
        - decisions
      summary: Decide
      description: >-
        Answer one or more `choice` questions about a context in a single call.
        Each question returns the selected option (or `null` when the model
        abstains), a probability per option, a confidence margin and an
        abstention status. The request id is returned in the `X-Request-ID`
        response header.
      operationId: decide
      parameters:
        - name: X-Request-ID
          in: header
          description: >-
            Optional client request id (1-128 chars of [A-Za-z0-9._:-]); echoed
            in the X-Request-ID response header
          required: false
          schema:
            type:
              - string
              - 'null'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DecideRequest'
            examples:
              label_only_intent:
                summary: Label-only intent (calibrated abstention)
                value:
                  context: I was charged twice for the same order
                  questions:
                    intent:
                      type: choice
                      options:
                        transaction_charged_twice: ''
                        card_arrival: ''
                        lost_or_stolen_card: ''
              multiple_questions:
                summary: Several questions answered in one call
                value:
                  context: Customer wants to return an item and asks about the refund.
                  questions:
                    department:
                      type: choice
                      options:
                        shipping: Shipping and delivery issues
                        returns: Returns and refunds
                        billing: Billing and payment issues
                    priority:
                      type: choice
                      options:
                        low: Can wait
                        normal: Normal priority
                        high: Needs quick attention
              single_question:
                summary: One question (options with descriptions)
                value:
                  context: Customer wants to return an item.
                  questions:
                    department:
                      type: choice
                      options:
                        shipping: Shipping and delivery issues
                        returns: Returns and refunds
                        billing: Billing and payment issues
              tool_routing:
                summary: Tool routing (advisory abstention)
                value:
                  context: Find my meetings tomorrow.
                  questions:
                    tool:
                      type: choice
                      task_type: tool
                      options:
                        calendar_search: Search calendar events
                        send_email: Send an email
        required: true
      responses:
        '200':
          description: One answer per question. Request id in the `X-Request-ID` header.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DecideResponse'
              examples:
                single_question:
                  value:
                    model: krun-one-v0
                    answers:
                      department:
                        type: choice
                        choice: returns
                        confidence: 0.9788
                        probabilities:
                          shipping: 0.0056
                          returns: 0.9866
                          billing: 0.0078
                        abstain: false
                        abstention_status: advisory
                    usage:
                      input_tokens: 52
                tool_routing:
                  value:
                    model: krun-one-v0
                    answers:
                      tool:
                        type: choice
                        choice: calendar_search
                        confidence: 0.965866
                        probabilities:
                          calendar_search: 0.982933
                          send_email: 0.017067
                        abstain: false
                        abstention_status: advisory
                    usage:
                      input_tokens: 41
        '400':
          description: INVALID_REQUEST / INVALID_OPTIONS
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBody'
              example:
                error:
                  code: INVALID_OPTIONS
                  message: >-
                    questions.department: 1 options given; between 2 and 64 are
                    required
                  request_id: req_0b7f7c5e9a3d4a8c9f1e2d3c4b5a6978
        '401':
          description: UNAUTHORIZED
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBody'
        '413':
          description: PAYLOAD_TOO_LARGE
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBody'
        '429':
          description: RATE_LIMITED / QUOTA_EXCEEDED
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBody'
        '502':
          description: INFERENCE_FAILED
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBody'
        '503':
          description: UPSTREAM_UNAVAILABLE
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBody'
        '504':
          description: UPSTREAM_TIMEOUT
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBody'
      security:
        - api_key: []
      x-codeSamples:
        - lang: python
          label: Python SDK
          source: |
            from krun import Krun

            client = Krun()  # reads KRUN_API_KEY

            result = client.decide(
                context="Customer wants to return an item.",
                questions={
                    "department": {
                        "type": "choice",
                        "options": {
                            "shipping": "Shipping and delivery issues",
                            "returns": "Returns and refunds",
                            "billing": "Billing and payment issues",
                        },
                    }
                },
            )

            answer = result.answers["department"]
            print(answer.choice, answer.confidence, result.request_id)
components:
  schemas:
    DecideRequest:
      type: object
      required:
        - context
        - questions
      properties:
        context:
          type: string
          description: The text to decide on (1–8,000 characters).
        questions:
          type: object
          description: >-
            Question id → question (1–16). Question ids (1–100 characters) are
            returned as keys of `answers`.
          additionalProperties:
            $ref: '#/components/schemas/Question'
          propertyNames:
            type: string
        model:
          type:
            - string
            - 'null'
          description: Optional; defaults to `krun-one-v0` (the only model available).
      additionalProperties: false
    DecideResponse:
      type: object
      description: >-
        Decision response. The request id is returned in the `X-Request-ID`
        header.
      required:
        - model
        - answers
        - usage
      properties:
        model:
          type: string
        answers:
          type: object
          description: Question id → answer, in request order.
          additionalProperties:
            $ref: '#/components/schemas/Answer'
          propertyNames:
            type: string
        usage:
          $ref: '#/components/schemas/Usage'
    ErrorBody:
      type: object
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/ErrorDetail'
    Question:
      type: object
      required:
        - type
        - options
      properties:
        type:
          $ref: '#/components/schemas/QuestionType'
        options:
          type: object
          description: >-
            Option id → description (2–64 options). Ids are returned as-is in
            `choice` and `probabilities`. Use `""`

            (or `null`) for label-only options.
          additionalProperties:
            type:
              - string
              - 'null'
          propertyNames:
            type: string
        task_type:
          oneOf:
            - $ref: '#/components/schemas/TaskType'
              description: >-
                `intent` (default) or `tool` (tool/function routing). Selects
                the model's instructions and the abstention

                status: tool routing is always `advisory`.
            - type: 'null'
      additionalProperties: false
    Answer:
      type: object
      required:
        - type
        - confidence
        - probabilities
        - abstain
        - abstention_status
      properties:
        type:
          $ref: '#/components/schemas/QuestionType'
          description: Always `choice`.
        choice:
          type:
            - string
            - 'null'
          description: >-
            Selected option id, or `null` when the model abstains (the best
            guess is still visible in `probabilities`).
        confidence:
          type: number
          format: double
          description: >-
            Margin between the two most likely options: top-1 probability minus
            top-2 probability, in [0, 1]. It is the score the abstention
            threshold is applied to, not the probability that `choice` is
            correct.
        probabilities:
          type: object
          description: Calibrated probability per option id, in request order.
          additionalProperties:
            type: number
            format: double
          propertyNames:
            type: string
        abstain:
          type: boolean
          description: True when `confidence` is below the abstention threshold.
        abstention_status:
          $ref: '#/components/schemas/AbstentionStatus'
          description: >-
            `calibrated` only for intent questions with label-only options;
            `advisory` otherwise (tool routing, intents

            with descriptions): abstention is then a hint, not a validated
            guarantee.
    Usage:
      type: object
      properties:
        input_tokens:
          type:
            - integer
            - 'null'
          format: int64
          description: >-
            Input tokens processed by the model (Krun One tokenizer, summed over
            the questions — each question is scored

            as its own sequence). `null` only if the backend did not report it.
          minimum: 0
    ErrorDetail:
      type: object
      required:
        - code
        - message
      properties:
        code:
          $ref: '#/components/schemas/ErrorCode'
          description: Stable machine-readable code.
        message:
          type: string
        request_id:
          type:
            - string
            - 'null'
          example: req_0b7f7c5e9a3d4a8c9f1e2d3c4b5a6978
    QuestionType:
      type: string
      enum:
        - choice
    TaskType:
      type: string
      enum:
        - intent
        - tool
    AbstentionStatus:
      type: string
      enum:
        - calibrated
        - advisory
    ErrorCode:
      type: string
      enum:
        - INVALID_REQUEST
        - INVALID_OPTIONS
        - PAYLOAD_TOO_LARGE
        - UNAUTHORIZED
        - NOT_FOUND
        - RATE_LIMITED
        - QUOTA_EXCEEDED
        - UPSTREAM_TIMEOUT
        - UPSTREAM_UNAVAILABLE
        - INFERENCE_FAILED
        - INTERNAL_ERROR
  securitySchemes:
    api_key:
      type: http
      scheme: bearer
      bearerFormat: krun_live_...

````