openapi: 3.1.0
info:
  title: Svift API
  version: "1.0"
  summary: Short, structured language outputs with per-field confidence.
  description: |
    Describe the fields you want back; every field comes back with its own confidence.
    See api.md for the full guide.
servers:
  - url: https://api.svift.ai
security:
  - apiKey: []

paths:
  /v1/run:
    post:
      operationId: run
      summary: Process text, images, and video into structured output fields
      description: |
        Every field is answered by a fast model, and enum fields also by a second model. Enum fields
        the models aren't confident enough in are answered again by both models with reasoning, and
        the majority wins (`effort: medium`). The hardest fields then go to a larger model
        (`effort: high`). Other fields are answered after the enum fields; a field with `when`
        only if the enum answers meet its condition. Costs one quota unit per answered field, or 2
        per answered field when `usage.input_tokens` is above 2,000. Media has no price of its own,
        but each picture adds tokens. Requests with media are answered without asking again.
        `max_effort` caps how far a request may go.

        The body is at most 1 MiB without media and 70 MiB with media. Send media as base64 in JSON,
        or as files in `multipart/form-data`: the first part is the JSON request, named `request`,
        and each media item names its file part with `part` instead of `data`. A video's sound track
        is ignored. Links are not accepted.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RunRequest"
            example:
              instructions: Classify this comment for moderation.
              input: BUY CHEAP PILLS at pills.example!!!
              output:
                label: {type: string, enum: [ok, spam, abuse]}
                severity: {type: integer, minimum: 0, maximum: 5}
                reason: {type: string, max_length: 80}
                tags: {type: array, items: {type: string, max_length: 20}, max_items: 5}
          multipart/form-data:
            schema:
              type: object
              required: [request]
              description: |
                `request` must be the first part. Every other part is a file named by exactly one
                media item's `part`; part names are free except `request`.
              properties:
                request:
                  $ref: "#/components/schemas/RunRequest"
              additionalProperties:
                type: string
                contentMediaType: application/octet-stream
            encoding:
              request:
                contentType: application/json
      responses:
        "200":
          description: Result
          headers:
            X-Request-Id:
              $ref: "#/components/headers/RequestId"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RunResponse"
              example:
                request_id: 019a0f3c-7d2e-7c41-9b8a-3f6e1d2c4b5a
                effort: low
                output:
                  label: {value: spam, confidence: 0.97}
                  severity: {value: 3, confidence: 0.91}
                  reason: {value: Unsolicited advertising for pills with a link, confidence: 0.93}
                  tags: {value: [advertising, pharma], confidence: null}
                usage: {input_tokens: 924, output_fields: 4}
        "400":
          $ref: "#/components/responses/InvalidRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "402":
          $ref: "#/components/responses/QuotaExceeded"
        "413":
          $ref: "#/components/responses/TooLarge"
        "415":
          $ref: "#/components/responses/UnsupportedMediaType"
        "500":
          $ref: "#/components/responses/InternalError"
        "502":
          $ref: "#/components/responses/UpstreamError"
        "503":
          $ref: "#/components/responses/Unavailable"
        "504":
          $ref: "#/components/responses/Timeout"

  /v1/quota:
    get:
      operationId: quota
      summary: Remaining quota of the account the API key belongs to
      description: |
        Costs nothing. All keys of an account share one balance. Requests still being processed
        aren't subtracted until they finish, and a top-up takes a few seconds to show. Also works
        on `https://api-eu.svift.ai`.
      responses:
        "200":
          description: Remaining quota
          headers:
            X-Request-Id:
              $ref: "#/components/headers/RequestId"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/QuotaResponse"
              example:
                request_id: 019a0f3c-7d2e-7c41-9b8a-3f6e1d2c4b5a
                quota: 9412
        "401":
          $ref: "#/components/responses/Unauthorized"
        "503":
          $ref: "#/components/responses/Unavailable"

  /health:
    get:
      operationId: health
      summary: Health check
      security: []
      responses:
        "204":
          description: The API is up.

components:
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: "API key: `svift_sk_` followed by 43 letters and digits."

  headers:
    RequestId:
      description: Unique ID of the request, the same as `request_id` in the body.
      schema:
        type: string

  schemas:
    RunRequest:
      type: object
      additionalProperties: false
      required: [output]
      properties:
        input:
          type: string
          description: |
            The text to process. Required and not blank unless `media` is set. At most 20,000
            tokens, or 4,000 tokens when media is attached.
        media:
          type: array
          maxItems: 16
          description: |
            Images (JPEG, PNG, or WebP, at most 10 MiB and 7680x4320 each) and at most one video
            (MP4, MOV, WebM, MKV, or GIF, at most 50 MiB, 3 minutes, and 3840x2160), at most 50 MiB
            together. The models see them in this order, before `input`. Images are scaled to at
            most 1024 pixels on their longest side. A video is shown as its most informative frame
            per 2-second span plus briefly shown frames, each labelled with its time; a request
            shows at most 48 pictures in total. The sound track is ignored.
          items:
            $ref: "#/components/schemas/Media"
        instructions:
          type: string
          description: What to do with the input. At most 4,000 tokens.
        max_effort:
          type: string
          enum: [low, medium, high]
          default: high
          description: |
            The highest `effort` the request may reach. `low`: no enum field is answered again.
            `medium`: enum fields may go through the reasoning step, but not to a larger model.
            `high`: no limit. A field that would have been answered again keeps the answer and
            confidence it had. The price is the same. Typical latency: `low` 0.2–0.5 s,
            `medium` 0.5–1.5 s, `high` 1–10 s.
        output:
          type: object
          description: |
            Requested fields, 1 to 16, returned in this order. Don't rely on one field's answer to
            decide another; use `when` to ask for a field only for some enum answers.
            Names match `^[a-z][a-z0-9_]{0,63}$` and must not end in `_confidence`.
          minProperties: 1
          maxProperties: 16
          propertyNames:
            pattern: "^[a-z][a-z0-9_]{0,63}$"
          additionalProperties:
            $ref: "#/components/schemas/Field"

    Media:
      type: object
      additionalProperties: false
      required: [type]
      description: Exactly one of `data` (JSON) or `part` (multipart/form-data).
      properties:
        type:
          type: string
          enum: [image, video]
        data:
          type: string
          contentEncoding: base64
          description: The file as standard base64 with padding, without a `data:` prefix.
        part:
          type: string
          description: Name of the multipart file part that holds the file. Only in multipart/form-data.

    Field:
      description: An output field definition. Options only apply to their own type.
      oneOf:
        - $ref: "#/components/schemas/StringField"
        - $ref: "#/components/schemas/IntegerField"
        - $ref: "#/components/schemas/FloatField"
        - $ref: "#/components/schemas/ArrayField"
      discriminator:
        propertyName: type
        mapping:
          string: "#/components/schemas/StringField"
          integer: "#/components/schemas/IntegerField"
          float: "#/components/schemas/FloatField"
          array: "#/components/schemas/ArrayField"

    Description:
      type: string
      maxLength: 512
      description: What the field means. The model reads it.

    When:
      type: object
      minProperties: 1
      description: >-
        Answer this field only when every named enum field's answer is one of its listed options.
        Keys are string fields with `enum` in the same request; options must be from their enum.
        Enum fields are answered first. When the condition isn't met, or a named field is unknown,
        no model is asked, the field is left out of `output`, and it isn't charged.
        Not allowed on enum fields or on array items.
      additionalProperties:
        type: array
        minItems: 1
        uniqueItems: true
        items: {type: string}

    StringField:
      type: object
      additionalProperties: false
      required: [type]
      description: Use either `enum` or `max_length`, not both. Text longer than the limit is truncated.
      properties:
        type: {const: string}
        description: {$ref: "#/components/schemas/Description"}
        enum:
          type: array
          minItems: 1
          maxItems: 256
          uniqueItems: true
          items: {type: string, minLength: 1, maxLength: 128}
        max_length:
          type: integer
          minimum: 1
          default: 128
          description: Character limit, per item for array items. Values above 256 are accepted and capped to 256.
        when: {$ref: "#/components/schemas/When"}

    IntegerField:
      type: object
      additionalProperties: false
      required: [type]
      properties:
        type: {const: integer}
        description: {$ref: "#/components/schemas/Description"}
        minimum: {type: integer, description: "Whole number between -2^53 and 2^53."}
        maximum: {type: integer, description: "Whole number between -2^53 and 2^53."}
        when: {$ref: "#/components/schemas/When"}

    FloatField:
      type: object
      additionalProperties: false
      required: [type]
      properties:
        type: {const: float}
        description: {$ref: "#/components/schemas/Description"}
        minimum: {type: number}
        maximum: {type: number}
        when: {$ref: "#/components/schemas/When"}

    ArrayField:
      type: object
      additionalProperties: false
      required: [type, items]
      properties:
        type: {const: array}
        description: {$ref: "#/components/schemas/Description"}
        items:
          description: Definition of each item. Arrays can't contain arrays.
          oneOf:
            - $ref: "#/components/schemas/StringField"
            - $ref: "#/components/schemas/IntegerField"
            - $ref: "#/components/schemas/FloatField"
        max_items:
          type: integer
          minimum: 1
          maximum: 128
          default: 128
        when: {$ref: "#/components/schemas/When"}

    RunResponse:
      type: object
      required: [request_id, effort, output, usage]
      properties:
        request_id:
          type: string
          description: Unique ID of the request (UUIDv7).
        effort:
          type: string
          enum: [low, medium, high]
          description: "`low`: no enum field was answered again. `medium`: at least one went through the reasoning step. `high`: at least one went to a larger model. Never above the request's `max_effort`."
        output:
          type: object
          description: One entry per requested field, in request order, except conditional fields whose `when` wasn't met.
          additionalProperties:
            $ref: "#/components/schemas/FieldResult"
        usage:
          type: object
          required: [input_tokens, output_fields]
          properties:
            input_tokens:
              type: integer
              description: >-
                The tokens in the request, counted once: instructions, input and output schema,
                plus the pictures when media is attached. Above 2,000, every field costs 2 quota
                units.
            output_fields:
              type: integer
              description: >-
                Number of fields returned. Each one is charged: 1 quota unit, or 2 when
                `usage.input_tokens` is above 2,000. Skipped conditional fields aren't counted.

    QuotaResponse:
      type: object
      required: [request_id, quota]
      properties:
        request_id:
          type: string
          description: Unique ID of the request (UUIDv7).
        quota:
          type: integer
          minimum: 0
          description: Remaining balance in field units, after everything charged so far. Never below 0.

    FieldResult:
      type: object
      required: [value, confidence]
      properties:
        value:
          description: The answer, or null when there is no valid one (then confidence is 0).
          oneOf:
            - type: string
            - type: integer
            - type: number
            - type: array
              items:
                oneOf: [{type: string}, {type: integer}, {type: number}]
            - type: "null"
        confidence:
          description: >-
            How likely the value is to be correct, from 0 to 0.99. As a guide, 0.9 and above is very
            high, 0.8 and above is high, 0.7 and above is medium, and below 0.7 is low. Always null
            for arrays, which aren't scored.
          type: [number, "null"]
          minimum: 0
          maximum: 0.99

    Error:
      type: object
      required: [request_id, error]
      properties:
        request_id:
          type: string
        error:
          type: object
          required: [type, message]
          properties:
            type:
              type: string
              enum: [invalid_request, unauthorized, quota_exceeded, internal_error, upstream_error, unavailable, timeout]
            message:
              type: string
            field:
              type: string
              description: Path of the request part that caused the error, e.g. `output.label.enum[2]` or `media[0].data`.

  responses:
    InvalidRequest:
      description: The request breaks a rule, or a file can't be used (such as a corrupt or too long video). Not charged.
      content:
        application/json:
          schema: {$ref: "#/components/schemas/Error"}
          example:
            request_id: 019a0f3c-7d2e-7c41-9b8a-3f6e1d2c4b5a
            error: {type: invalid_request, message: must be at least 1, field: output.reason.max_length}
    Unauthorized:
      description: API key missing, malformed, unknown, or revoked.
      content:
        application/json:
          schema: {$ref: "#/components/schemas/Error"}
    QuotaExceeded:
      description: >-
        Not enough quota for this request: one unit per field, or 2 per field when it could be
        above 2,000 input tokens. Not charged. `GET /v1/quota` shows what's left.
      content:
        application/json:
          schema: {$ref: "#/components/schemas/Error"}
    TooLarge:
      description: Request body larger than 1 MiB without media, or 70 MiB with media.
      content:
        application/json:
          schema: {$ref: "#/components/schemas/Error"}
    UnsupportedMediaType:
      description: Content-Type is neither application/json nor multipart/form-data.
      content:
        application/json:
          schema: {$ref: "#/components/schemas/Error"}
    InternalError:
      description: Unexpected error. Retry with backoff.
      content:
        application/json:
          schema: {$ref: "#/components/schemas/Error"}
    UpstreamError:
      description: The model couldn't produce a result, or a file couldn't be processed. Not charged; retry with backoff.
      content:
        application/json:
          schema: {$ref: "#/components/schemas/Error"}
    Unavailable:
      description: A backend is temporarily down, or too many large uploads are being processed. Not charged; retry with backoff.
      content:
        application/json:
          schema: {$ref: "#/components/schemas/Error"}
    Timeout:
      description: The request took too long. Not charged; retry or send a shorter input or video.
      content:
        application/json:
          schema: {$ref: "#/components/schemas/Error"}
