openapi: 3.1.0
info:
  title: SlashInfra SVM API
  version: 0.1.0
  description: >
    Run programs, read and write files, and open a terminal on one SVM.

    Each SVM has a host at `https://<id>.slashinfra.dev`. Send an API key with each
    request. The first request starts the SVM. A request also wakes an SVM that is
    stopped or paused.

    A preview host is `https://<port>-<id>.slashinfra.dev`. It sends requests to the
    TCP port in the SVM. The app keeps its own `Authorization` header, so send the
    API key in `X-Si-Authorization`. A `closed` port accepts organization members.
    An `authenticated` port also accepts an expiring preview link. A `public` port
    accepts anyone. Requests to a preview host go to the app on that port.

    Use the control API to create, list or delete an SVM and run its `start`, `stop`
    or `pause` action: [Create an SVM](/docs/api-reference/control/svms#postSvms),
    [Delete an SVM](/docs/api-reference/control/svms#deleteSvmsById).


    ## Authentication


    Send the key as `Authorization: Bearer si_...` on an SVM host. On a preview

    host, send it as `X-Si-Authorization: Bearer si_...`.


    `si login` saves a device key. The [dashboard](https://app.slashinfra.com/keys)
    creates an organization key and shows its secret once. A key starts with `si_`
    and has 43 base64url characters after the prefix.


    <a id="answers-of-the-api-gateway"></a>

    ## API responses


    - `401`: no key, an invalid key, or a deleted key. The body is `unauthorized`, and
      the reply carries `WWW-Authenticate: Bearer`.
    - `404`: the host label is not an SVM id, no such SVM, an SVM that is
      being deleted, or an SVM of another organization. The body is `not_found` in
      each case.
    - `503`: the SVM could not be reached. The body is `the SVM could not be
      reached`.

    Deletion and key revocation follow the [credential propagation
    period](/docs/reference/limits#credentials).


    ## Bodies


    Request bodies are raw bytes. `POST` uses the body as the program's standard input;
    `PUT` writes it as a file. Replies use `text/plain; charset=utf-8` by default.
    File replies use the type from the file extension. Arguments and settings go in
    the query string; the API does not accept JSON request bodies.

    Send `Accept: application/json` for JSON directory listings and errors. A
    directory is an array of `{name, type, size, mode, mtime}`. An error is
    `{error, code}`; see [Errors](/docs/reference/errors). A file GET
    returns a weak `ETag` and `Last-Modified`. `If-None-Match` can return `304`; a
    `PUT` with `If-Match` returns `412` if the file changed. Every response includes
    `Cache-Control: private` and `Referrer-Policy: no-referrer`.
servers:
  - url: https://{id}.slashinfra.dev
    description: An SVM host. Replace `id` with the SVM id.
    variables:
      id:
        default: 6f1c0f0e8a
        description: 'The SVM id: ten symbols of `0123456789abcdefghjkmnpqrstvwxyz`.'
  - url: https://{port}-{id}.slashinfra.dev
    description: A preview host. It sends every request to `port` in the SVM.
    variables:
      port:
        default: '8080'
        description: The TCP port in the SVM, from 1 to 65535.
      id:
        default: 6f1c0f0e8a
        description: 'The SVM id: ten symbols of `0123456789abcdefghjkmnpqrstvwxyz`.'
security:
  - apiKey: []
tags:
  - name: Files
    description: Files and directories of one SVM.
  - name: Exec
    description: Run a program in one SVM.
  - name: Terminal
    description: The interactive terminals of one SVM.
paths:
  /{path}:
    get:
      operationId: readPath
      summary: Read a path
      description: >
        Returns a file or a directory listing, and wakes the SVM if it sleeps.
        A file above the [file listing limit](/docs/reference/limits#files) gets `413` when the API reads it as a listing; read a part with `Range`, or copy it with `si cp`.
      tags:
        - Files
      parameters:
        - name: path
          in: path
          required: true
          description: |
            The path in the SVM, without the first `/` (`/` is the root); the API percent-decodes it, resolves `.` and `..`, and a trailing `/` names a directory.
          schema:
            type: string
            example: /home/user/notes.txt
        - name: Range
          in: header
          required: false
          description: |
            One byte range of a file: `bytes=10-19` (bytes 10 to 19), `bytes=90-` (byte 90 to the end) or `bytes=-5` (the last 5 bytes); any other form returns the whole file, and a range on a directory is ignored.
          schema:
            type: string
            example: bytes=10-19
        - name: If-None-Match
          in: header
          required: false
          description: |
            A weak `ETag` from an earlier GET; when the file did not change, the answer is `304` with the same `ETag` and no content, and `*` matches any file.
          schema:
            type: string
            example: 'W/"1234-5-1720000000000000000"'
        - name: Accept
          in: header
          required: false
          description: |
            `application/json` makes a directory listing a JSON array and an error a `{error, code}` body; any other value keeps the text listing.
          schema:
            type: string
            enum:
              - application/json
        - name: watch
          in: query
          required: false
          description: |
            `?watch` streams the changes of this path as Server-Sent Events for up to the plan's stream limit, each with `path` and `kind` (`created`, `modified`, `deleted` or `moved`); a directory watches its whole tree, changes to one path within 100 ms coalesce, and the stream keeps the SVM awake.
          schema:
            type: boolean
      responses:
        '200':
          description: 'The file, or the listing of a directory as `ls -la` does it, or a JSON array with `Accept: application/json`.'
          headers:
            Cache-Control:
              description: '`private`: the answer may be cached only by the calling client.'
              schema:
                type: string
            ETag:
              description: |
                A weak `ETag` that identifies the file version; treat it as an opaque value.
              schema:
                type: string
            Last-Modified:
              description: The modification time of a file, as an HTTP date.
              schema:
                type: string
            Accept-Ranges:
              description: '`bytes`: `Range` works on every file.'
              schema:
                type: string
            Content-Security-Policy:
              description: |
                The sandbox policy of a file of the SVM, `sandbox allow-scripts allow-forms allow-popups allow-modals`, which gives the file an opaque origin so its scripts cannot call the SVM API.
              schema:
                type: string
            Content-Type:
              description: |
                The type of the file extension, else `text/plain; charset=utf-8` for UTF-8 content and `application/octet-stream` otherwise; a directory listing is `text/plain; charset=utf-8`.
              schema:
                type: string
            X-Content-Type-Options:
              description: '`nosniff`: a browser does not guess another type.'
              schema:
                type: string
          content:
            text/plain:
              schema:
                type: string
            application/json:
              schema:
                type: array
                description: 'The entries of a directory, with `Accept: application/json`.'
                items:
                  type: object
                  required:
                    - name
                    - type
                    - size
                    - mode
                    - mtime
                  properties:
                    name:
                      type: string
                      example: notes.txt
                    type:
                      type: string
                      enum:
                        - file
                        - dir
                        - symlink
                        - other
                    size:
                      type: integer
                      minimum: 0
                      description: The size in bytes; a directory's size is its own file-system metadata size, not the total size of its contents.
                    mode:
                      type: integer
                      description: The Unix permission bits as a number (`420` is `0644`).
                      example: 420
                    mtime:
                      type: integer
                      description: The modification time in seconds since the Unix epoch.
            application/octet-stream:
              schema:
                type: string
                contentMediaType: application/octet-stream
            text/html:
              schema:
                type: string
        '304':
          description: The file did not change since the `ETag` in `If-None-Match`; no content follows.
          headers:
            Cache-Control:
              description: '`private`.'
              schema:
                type: string
            ETag:
              description: The weak `ETag` of the file.
              schema:
                type: string
            Last-Modified:
              description: The modification time of the file, as an HTTP date.
              schema:
                type: string
        '206':
          description: The part of the file that `Range` asks for.
          headers:
            Accept-Ranges:
              description: '`bytes`.'
              schema:
                type: string
            Content-Range:
              description: '`bytes 10-19/100`: the part and the size of the file.'
              schema:
                type: string
            Content-Security-Policy:
              description: The sandbox policy of a file of the SVM.
              schema:
                type: string
            Content-Type:
              description: The type of the file extension.
              schema:
                type: string
            ETag:
              description: The weak `ETag` of the whole file.
              schema:
                type: string
            Last-Modified:
              description: The modification time of the file, as an HTTP date.
              schema:
                type: string
            X-Content-Type-Options:
              description: '`nosniff`.'
              schema:
                type: string
        '403':
          description: |
            `permission denied`: the SVM's account `user` may not read the file or
            enter a directory of the path, or the path leaves the grant's scope.
            Make the file readable, or use a path that `user` may read.
          content:
            text/plain:
              schema:
                type: string
        '404':
          description: |
            `not_found`: the host label is not an SVM id, the SVM does not exist, it is
            being deleted, or it belongs to another organization. The response is the
            same in each case. `svm: /path: No such file or directory` means that the
            path does not exist, or a file in the path is used as a directory (`Not a
            directory`). Check the path with `si exec <svm> -- ls -la <dir>`.
          content:
            text/plain:
              schema:
                type: string
        '405':
          description: |
            `method_not_allowed` for a method other than `GET`, `POST`, `PUT` or `PATCH`.
            `DELETE` answers `an SVM is deleted through the control plane, not on its
            own host`. Use `DELETE /svms/<id>` on the control API.
          content:
            text/plain:
              schema:
                type: string
        '413':
          description: >
            `file too large`: the file is above the [file transfer limit](/docs/reference/limits#files). Or
            `file of more than

            16777216 bytes: GET returns at most that much`: the API read a file of

            more than the [file listing limit](/docs/reference/limits#files) as a listing. Read a part with
            `Range`, or copy the file

            with `si cp <svm>:<path> -`.
          content:
            text/plain:
              schema:
                type: string
        '416':
          description: |
            The range starts at or past the end of the file, for example a log poll with
            no new bytes. The body is empty and `Content-Range` gives the size:
            `bytes */100`. Poll again later, or remove the `Range` header.
          headers:
            Content-Range:
              description: '`bytes */<size>`: the size of the file.'
              schema:
                type: string
        '429':
          description: >
            `this computer is busy; try again soon`: the [concurrent request
            limit](/docs/reference/limits#resources) is in use. Retry after `Retry-After` seconds.
          headers:
            Retry-After:
              description: Seconds to wait. `1`.
              schema:
                type: string
        '500':
          description: |
            `download failed`, `empty reply from the SVM`, or the error text of
            `ls` or `cat`. Retry. If the error repeats, create a new SVM.
          content:
            text/plain:
              schema:
                type: string
        '503':
          $ref: '#/components/responses/Unreachable'
      x-codeSamples:
        - lang: bash
          label: si
          source: si cp :/var/log/jobs/3.log -
        - lang: bash
          label: curl
          source: 'curl -sS "https://6f1c0f0e8a.slashinfra.dev/var/log/jobs/3.log" -H "Authorization: Bearer
            $SI_API_KEY"'
    put:
      operationId: uploadFile
      summary: Upload a file
      description: >
        Writes the request body to a file atomically, within the [file transfer limit](/docs/reference/limits#files). The parent directory must exist and a replaced file keeps its mode and owner; see [files and programs](/docs/build/files-and-programs) for new-file modes and the executable bit.
      tags:
        - Files
      parameters:
        - name: path
          in: path
          required: true
          description: The path of the file; its parent directory must exist.
          schema:
            type: string
            example: /home/user/notes.txt
        - name: If-None-Match
          in: header
          required: false
          description: |
            `*` creates the file only if it does not exist, and an existing file gets `412`.
          schema:
            type: string
            enum:
              - '*'
        - name: If-Match
          in: header
          required: false
          description: |
            A weak `ETag` from an earlier GET; if the file changed, the API returns `412` and does not write, and `*` requires the file to exist.
          schema:
            type: string
            example: 'W/"1234-5-1720000000000000000"'
        - name: Content-Length
          in: header
          required: false
          description: >
            The size of the body in bytes; without it the API reads until the body ends, and a value above the [file transfer limit](/docs/reference/limits#files) gets `413` before the body is read.
          schema:
            type: integer
            minimum: 0
            maximum: 99614720
      requestBody:
        required: true
        description: The raw bytes of the file. The `Content-Type` of the request is ignored.
        content:
          application/octet-stream:
            schema:
              type: string
              contentMediaType: application/octet-stream
      responses:
        '201':
          description: The file did not exist and is now written. The body is empty.
          headers:
            Server-Timing:
              description: The wake and command phases of the request.
              schema:
                type: string
        '204':
          description: The file existed and is replaced. The body is empty.
          headers:
            Server-Timing:
              description: The wake and command phases of the request.
              schema:
                type: string
        '400':
          description: '`invalid path`: the path contains a NUL byte. Use a path without a NUL byte.'
          content:
            text/plain:
              schema:
                type: string
        '403':
          description: |
            The body is empty. `user` may not write the file or the directory, or the
            path leaves the grant's scope. Change the mode or the owner with `si exec
            <svm> -- chmod`, or write to `/home/user`.
        '404':
          description: |
            The body is empty. The parent directory does not exist. Create it with `si
            exec <svm> -- mkdir -p <dir>`.
        '408':
          description: |
            `upload timed out`: the upload did not finish in time. Retry with a stable
            connection. An empty body means that the body stalled for more than 30
            seconds.
          content:
            text/plain:
              schema:
                type: string
        '409':
          description: The body is empty. The path is a directory. Use a file path, or `POST` to run a program
            in the directory.
        '412':
          description: 'The body is empty. `If-None-Match: *` and the file exists, or the file no longer has the
            `If-Match` ETag. Read or delete the file first.'
        '413':
          description: >
            `file too large`: the body is above the [file transfer limit](/docs/reference/limits#files), from
            `Content-Length` or

            while it streamed. Send less, or split the file.
          content:
            text/plain:
              schema:
                type: string
        '429':
          description: '`this computer is busy; try again soon`: the [concurrent request
            limit](/docs/reference/limits#resources) is in use. Retry after `Retry-After` seconds.'
          headers:
            Retry-After:
              description: Seconds to wait. `1`.
              schema:
                type: string
        '500':
          description: The body is empty. The SVM could not write the file. Retry; if it repeats, create a new SVM.
        '503':
          $ref: '#/components/responses/Unreachable'
        '507':
          description: The body is empty. The disk is full. Remove files with `si exec <svm> -- rm`.
      x-codeSamples:
        - lang: bash
          label: si
          source: si cp notes.txt :notes.txt
        - lang: bash
          label: curl
          source: 'curl -sS -T notes.txt "https://6f1c0f0e8a.slashinfra.dev/home/user/notes.txt" -H
            "Authorization: Bearer $SI_API_KEY"'
    patch:
      operationId: writeAtOffset
      summary: Write at an offset
      description: >
        Writes the request body at a byte offset instead of replacing the file, and an append starts at the current size. Concurrent PATCH and PUT requests in one directory do not interleave, and an offset past the end of the file or the [file transfer limit](/docs/reference/limits#files) returns `416`; PATCH never leaves a hole.
      tags:
        - Files
      parameters:
        - name: path
          in: path
          required: true
          description: The file to write; it must exist, and a missing file gets `404`.
          schema:
            type: string
            example: /var/log/jobs/3.log
        - name: Content-Range
          in: header
          required: true
          description: |
            `bytes <start>-*/*`, the byte offset of the first body byte; only this form is accepted, and a bounded range or a suffix gets `400`.
          schema:
            type: string
            example: bytes 100-*/*
        - name: Content-Length
          in: header
          required: false
          description: The size of the body in bytes.
          schema:
            type: integer
            minimum: 0
            maximum: 99614720
      requestBody:
        required: true
        description: The bytes to write at the offset.
        content:
          application/octet-stream:
            schema:
              type: string
              contentMediaType: application/octet-stream
      responses:
        '204':
          description: The bytes are written. The body is empty.
          headers:
            Server-Timing:
              description: The wake and command phases of the request.
              schema:
                type: string
        '400':
          description: '`Content-Range: bytes <start>-*/* is required`: another form, or no such header.'
          content:
            text/plain:
              schema:
                type: string
        '403':
          description: The body is empty. `user` may not write the file, or the path leaves the grant's scope.
        '404':
          description: The body is empty. The file or its parent directory does not exist.
        '409':
          description: The body is empty. The path is a directory.
        '413':
          description: The body is above the file transfer limit, or the write would pass it.
          content:
            text/plain:
              schema:
                type: string
        '416':
          description: The offset is past the end of the file or past the file limit. Nothing was written.
          headers:
            Content-Range:
              description: '`bytes */<size>`: the size of the file.'
              schema:
                type: string
        '429':
          description: '`this computer is busy; try again soon`: the concurrent request limit is in use.'
          headers:
            Retry-After:
              description: Seconds to wait. `1`.
              schema:
                type: string
        '507':
          description: The body is empty. The disk is full.
        '503':
          $ref: '#/components/responses/Unreachable'
      x-codeSamples:
        - lang: bash
          label: curl
          source: 'curl -sS -X PATCH "https://6f1c0f0e8a.slashinfra.dev/var/log/jobs/3.log" -H "Authorization:
            Bearer $SI_API_KEY" -H "Content-Range: bytes 100-*/*" --data-binary @chunk'
    post:
      operationId: runProgram
      summary: Run a program
      description: >
        Runs the executable at `path` as a new process of `user`: the request body is its standard input, and the reply is its standard output and error together. A non-zero `X-Exit-Code` still answers `200`, the [command limits](/docs/reference/limits#commands) set the timeouts and stream sizes, and [background work](/docs/build/background-work) covers longer jobs.
      tags:
        - Exec
      parameters:
        - name: path
          in: path
          required: true
          description: |
            The executable file, where a directory gets `405` and `/usr/bin/env` finds the program in `PATH`.
          schema:
            type: string
            example: /usr/bin/env
        - name: arg
          in: query
          required: false
          description: |
            One argument of the program, repeated for each in order; the query is form-encoded (`+` is a space and `%2B` a plus), with at most 512 KiB of arguments together and `400` for a NUL byte.
          style: form
          explode: true
          schema:
            type: array
            items:
              type: string
            example:
              - ls
              - -la
        - name: cwd
          in: query
          required: false
          description: |
            The working directory, an absolute path that exists and that `user` may enter, else `404` or `403`; the default is `/home/user`.
          schema:
            type: string
            default: /home/user
            example: /tmp
        - name: env
          in: query
          required: false
          description: |
            One environment variable of this process as `KEY=value`, repeated for each; the value is split at its first `=`. A name may appear once per request and follows the environment rules of the SVM (`400` otherwise, and for a NUL byte). It overrides the stored environment of the SVM for this process only and never changes it.
          style: form
          explode: true
          schema:
            type: array
            items:
              type: string
            example:
              - DEBUG=1
        - name: timeout
          in: query
          required: false
          description: |
            The timeout of the program in seconds, from 1 to 30 with a default of 30: a value outside the range gets `400`, and at the timeout the API ends the process group and returns the output so far.
          schema:
            type: integer
            minimum: 1
            maximum: 30
            default: 30
            example: 30
      requestBody:
        required: false
        description: >
          The standard input of the program, within the [command input and output
          limits](/docs/reference/limits#commands). Without `Content-Length` the

          API reads until the body ends. With `Accept: text/event-stream` the body
          streams under the [transfer rates](/docs/reference/limits#files)
          and has no 1 MiB cap.
        content:
          application/octet-stream:
            schema:
              type: string
              contentMediaType: application/octet-stream
      responses:
        '200':
          description: |
            The output of the program. A non-zero `X-Exit-Code` is a failed program, not
            a failed request. A timeout sets `X-Timeout: 1` and `X-Exit-Code: 124`.
          headers:
            X-Exit-Code:
              description: |
                The exit code of the program, also on `200`: `124` at a timeout, and `128 + signal` when a signal kills it (`137` for `SIGKILL`).
              schema:
                type: integer
                example: 0
            X-Timeout:
              description: |
                `1` when the request timeout ended the program, with `X-Exit-Code` `124`; the header is absent otherwise, also when a program exits with `124` itself.
              schema:
                type: string
            X-Truncated:
              description: '`1` when the output was cut at 1 MiB; the header is absent otherwise.'
              schema:
                type: string
            Server-Timing:
              description: The wake and command phases of the request.
              schema:
                type: string
            Location:
              description: |
                `/var/log/jobs/<n>.log` when this POST started a job with `/usr/bin/job`, the log that the start line prints (also with `-q`); absent otherwise.
              schema:
                type: string
                example: /var/log/jobs/3.log
          content:
            text/plain:
              schema:
                type: string
            application/json:
              schema:
                type: object
                required: [exit, stdout, stderr, truncated, timed_out]
                properties:
                  exit:
                    type: integer
                    description: The exit code of the program; `124` at a timeout.
                    example: 0
                  stdout:
                    type: string
                    description: Standard output, as UTF-8 with `U+FFFD` for bytes that are not.
                  stderr:
                    type: string
                    description: Standard error, as UTF-8 with `U+FFFD` for bytes that are not.
                  truncated:
                    type: boolean
                    description: '`true` when either stream reached the command output limit.'
                  timed_out:
                    type: boolean
                    description: '`true` when the request timeout ended the program; `exit` is then `124`.'
            text/event-stream:
              schema:
                type: string
              description: |
                `stdout` and `stderr` events whose `data` is one JSON-encoded chunk
                (`{"encoding":"base64","data":"..."}` for bytes that are not UTF-8),
                then one `exit` event `{"code":N,"timed_out":bool}` from SlashInfra.
        '400':
          description: |
            `invalid path` (a NUL byte in the path), `invalid cwd` (not absolute, or
            more than 4096 bytes), `timeout must be 1 to 30 seconds`, or `an argument
            contains NUL`. Send a valid value.
          content:
            text/plain:
              schema:
                type: string
        '403':
          description: |
            `svm: /path: Permission denied`: the file is not executable, or `user`
            may not enter the directory. Set the executable bit with `si exec <svm>
            -- chmod +x <path>`.
          content:
            text/plain:
              schema:
                type: string
        '404':
          description: |
            `svm: /path: No such file or directory`: the file or the working
            directory is missing. Check it with `si exec <svm> -- ls -la`.
          content:
            text/plain:
              schema:
                type: string
        '405':
          description: '`svm: /path: Is a directory`: the path is a directory. Use an executable file.'
          content:
            text/plain:
              schema:
                type: string
        '408':
          description: '`input stalled`: the body stopped for more than 30 seconds. Retry with a stable
            connection.'
          content:
            text/plain:
              schema:
                type: string
        '413':
          description: |
            `arguments or input too large`: more than 1 MiB of input, or more than
            512 KiB of arguments. `input too large`: the streamed body went over 1 MiB
            with no `Content-Length`. Send less.
          content:
            text/plain:
              schema:
                type: string
        '429':
          description: '`this computer is busy; try again soon`: the [concurrent request
            limit](/docs/reference/limits#resources) is in use. Retry after `Retry-After` seconds.'
          headers:
            Retry-After:
              description: Seconds to wait. `1`.
              schema:
                type: string
        '500':
          description: |
            `the SVM crashed during the command; its disk is back at the last
            snapshot`: the command crashed the SVM; changes since the last complete
            snapshot are lost. Or `empty reply from the SVM`: retry; if it repeats,
            create a new SVM.
          content:
            text/plain:
              schema:
                type: string
        '503':
          $ref: '#/components/responses/Unreachable'
      x-codeSamples:
        - lang: bash
          label: si
          source: si exec -- ls -la /tmp
        - lang: bash
          label: curl
          source: 'curl -sS -X POST "https://6f1c0f0e8a.slashinfra.dev/usr/bin/env?arg=ls&arg=-la&arg=/tmp" -H
            "Authorization: Bearer $SI_API_KEY"'
        - lang: bash
          label: curl (stream)
          source: 'curl -sS -N -X POST "https://6f1c0f0e8a.slashinfra.dev/bin/bash" -H
            "Authorization: Bearer $SI_API_KEY" -H "Accept: text/event-stream" --data-binary
            "echo out; echo err >&2; sleep 2"'
  /bin/{program}:
    get:
      operationId: openTerminal
      summary: Open a terminal
      description: |
        Opens a terminal of the SVM as `user` in `/home/user` over a WebSocket upgrade; the path picks the program, such as `bash` or an agent. Closing the connection ends the program unless it is an `hc` terminal, and a presence message counts as a person for the [sleep policy](/docs/how/sleep-and-wake), and the [shell tool](/docs/build/shell-tool) covers the protocol.
      tags:
        - Terminal
      parameters:
        - name: program
          in: path
          required: true
          description: |
            The terminal program. `bash` is a login shell. `zellij`, `tmux` and `herdr`
            are multiplexers and `hc` is the herdr-core API. `claude`, `codex` and `opencode` are coding
            agents that take their arguments from `arg`.
          schema:
            type: string
            enum:
              - bash
              - zellij
              - tmux
              - herdr
              - hc
              - claude
              - codex
              - opencode
            example: bash
        - name: arg
          in: query
          required: false
          description: |
            One argument of an agent program (`claude`, `codex` or `opencode`), repeated in order for up to 16 values; `arg` holds only the agent's own options and prompt, and each value is passed as one argument with the quoting that the agent's own parser needs.
          style: form
          explode: true
          schema:
            type: array
            maxItems: 16
            items:
              type: string
            example:
              - --resume
              - 9f2c1a
        - name: Upgrade
          in: header
          required: false
          description: |
            `websocket` opens the interactive terminal, and without this header the request returns the terminal page or the program file.
          schema:
            type: string
            enum:
              - websocket
      responses:
        '101':
          description: |
            The protocol switches to WebSocket. Binary frames carry terminal input and
            output; a text frame with `{"cols":80,"rows":24}` resizes the terminal.
        '200':
          description: |
            The terminal page when `Accept` contains `text/html`, or the program file.
            This answer opens no terminal; send a WebSocket upgrade for that.
          content:
            text/html:
              schema:
                type: string
            application/octet-stream:
              schema:
                type: string
                contentMediaType: application/octet-stream
        '400':
          description: |
            `too many arguments`: more than 16 `arg` values. `an argument contains NUL`:
            remove the NUL byte. Both apply to the agent programs. `invalid tab`: an
            `hc` WebSocket request needs a `tab` of 1-32 characters of `a-z`, `0-9`, `-`
            and `_`.
          content:
            text/plain:
              schema:
                type: string
        '413':
          description: |
            `arguments too large`: the arguments of an agent program are more than
            512 KiB together. Send fewer or shorter arguments.
          content:
            text/plain:
              schema:
                type: string
        '429':
          description: >
            `terminal connection limit reached`: the [terminal connection
            limit](/docs/reference/limits#connections) is in use. Close one, or retry after `Retry-After`
            seconds.
          headers:
            Retry-After:
              description: Seconds to wait. `1`.
              schema:
                type: string
        '503':
          $ref: '#/components/responses/Unreachable'
      x-codeSamples:
        - lang: bash
          label: si
          source: si shell --program zellij
components:
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: >
        An API key on an SVM host: `si_` and 43 base64url characters, sent as `Authorization: Bearer si_...`; the [dashboard](https://app.slashinfra.com/keys) shows an organization key once, and a deleted key stops working after the [credential propagation period](/docs/reference/limits#credentials).
    previewKey:
      type: apiKey
      in: header
      name: X-Si-Authorization
      description: |
        The API key on a preview host, sent as `X-Si-Authorization: Bearer si_...`; SlashInfra removes this header before the request reaches the SVM, so the app keeps its own `Authorization` header.
  responses:
    Unauthorized:
      description: |
        `unauthorized`: the request has no key, an invalid key, or a deleted key. `si
        login` saves a valid key.
      headers:
        WWW-Authenticate:
          description: '`Bearer`.'
          schema:
            type: string
        Cache-Control:
          description: '`no-store`.'
          schema:
            type: string
      content:
        text/plain:
          schema:
            type: string
    NotFound:
      description: |
        `not_found`: the host label is not an SVM id, no such SVM, an SVM that
        is being deleted, or an SVM of another organization. The body is the same
        for all of them. Run `si ls` to see the SVMs of the key.
      content:
        text/plain:
          schema:
            type: string
    Unreachable:
      description: >
        `the SVM could not be reached`: SlashInfra could not reach the SVM. Retry. The SVM
        may also return `too many SVMs are awake; try again soon` when capacity is full,
        `the SVM did not answer in time` when a directory listing times out, `the server
        is stopping` while it restarts, a preview error (`nothing listens on port N in
        this computer`, `the SVM did not speak HTTP`, or `the SVM did not answer`), or
        other host error text.

        A file read that cannot read its data returns `503`. The SVM stays running, and
        a later retry may succeed.
      content:
        text/plain:
          schema:
            type: string
