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

# Create Asset Upload

> Step 1 of 3. Reserves an asset record and mints a signed upload URL.
The client must then PUT the exact bytes to `upload_url` (step 2) and
call `POST /v1/assets/{id}/complete` (step 3) to hand off to
the ingest pipeline.

When the request includes the file's hex-encoded `md5` and content
with that digest already exists in the project, the server skips the
upload: it returns `200` with `already_exists: true`, the existing
`asset_id`, and its current `status`, and omits the upload fields.
A first upload (or a prior upload that failed ingest) returns `201`
with the signed-URL fields.




## OpenAPI

````yaml /openapi.yaml post /v1/assets
openapi: 3.0.3
info:
  title: Chief Public API
  version: 1.0.0
  contact:
    name: Chief Support
    url: https://chief.bot
  description: |
    Chief's public REST API for programmatic access to chats and assets.

    All endpoints are authenticated with a Personal Access Token (PAT)
    sent in the `X-API-Key` header. PATs are minted out-of-band from the
    Chief settings UI.

    All endpoints that touch project-scoped resources require the
    `X-Project-Id` header. Missing or invalid project IDs respond with HTTP
    400 and the error code `publicapi.tenancy.project.missing`.

    ## Error envelope

    Every error response uses the same JSON envelope:

    ```json
    { "code": "publicapi.auth.invalid",
      "humane": "The provided API key is invalid or has been revoked.",
      "statusCode": 401 }
    ```

    `code` is a stable, dotted, lowercase identifier suitable for client-side
    i18n and analytics. `humane` is plain English safe to surface to end
    users. `statusCode` mirrors the HTTP status.

    ## Chat workflow — kickoff + poll

    Chats are asynchronous in v1. Callers need to poll the
    per-message endpoint until the content they need is present.

    1. `POST /v1/chats` with `{prompt}`. The server kicks off the
       workflow and returns `{chat_id, message_id, created_at}`
       immediately. `message_id` is the message you'll poll.
    2. `POST /v1/chats/{chat_id}/messages` with `{prompt}` to
       continue an existing chat — appends a new turn and returns
       `{message_id, created_at}`.
    3. `GET /v1/chats/{chat_id}/messages/{message_id}` to read the
       message. While the workflow is still writing, `prompt` and
       `response` are omitted; once written they're present. Treat the
       appearance of `response` as the signal that the assistant has
       produced output.
    4. `GET /v1/chats/{chat_id}` returns chat-level metadata only
       (`modified_at`). It does not carry messages.
    5. `GET /v1/chats/{chat_id}/messages` lists every message's id +
       `created_at` (no content); clients fetch one message at a time via
       `GET /v1/chats/{chat_id}/messages/{mid}` for the prompt + response
       body.

    ## Asset workflow — three-step upload

    Assets are uploaded directly to blob storage via a signed URL. The flow
    is:

    1. `POST /v1/assets` with `{filename, mime_type}`, optionally including
       the hex-encoded `md5` of the file. When `md5` matches content already
       in the project the server returns `200` with `already_exists: true` and
       no upload URL — skip to fetching the asset. Otherwise it returns `201`
       with `{asset_id, upload_url, upload_method:"PUT", upload_headers,
       expires_at}`.
    2. `PUT` the file bytes to `upload_url`, applying every header in
       `upload_headers` verbatim. The URL is valid until `expires_at`.
    3. `POST /v1/assets/{asset_id}/complete` with an empty body to
       hand the asset off to the ingest pipeline. The server reads the
       uploaded object's size and MD5 from blob storage at this step. The
       response carries the current `AssetResponse`; clients poll until
       `status` is `ready` or `failed`.
servers:
  - url: '{baseUrl}'
    description: Chief
    variables:
      baseUrl:
        default: https://api.storytell.ai
        description: Base URL of the deployment serving the API.
security:
  - apiKey: []
tags:
  - name: Chats
    description: Public chat lifecycle — kickoff, list, fetch.
  - name: Assets
    description: Public asset upload + ingest lifecycle.
  - name: Labels
    description: Public label CRUD and asset-label attachment.
  - name: Actions
    description: Public action CRUD plus enable/disable.
  - name: Sessions
    description: Public recording-session listing and CRUD.
  - name: Skills
    description: Public skill CRUD plus enable/disable.
  - name: Memories
    description: Public memory CRUD.
  - name: Projects
    description: Public project create/edit, membership, and invitations.
paths:
  /v1/assets:
    post:
      tags:
        - Assets
      summary: Create Asset Upload
      description: |
        Step 1 of 3. Reserves an asset record and mints a signed upload URL.
        The client must then PUT the exact bytes to `upload_url` (step 2) and
        call `POST /v1/assets/{id}/complete` (step 3) to hand off to
        the ingest pipeline.

        When the request includes the file's hex-encoded `md5` and content
        with that digest already exists in the project, the server skips the
        upload: it returns `200` with `already_exists: true`, the existing
        `asset_id`, and its current `status`, and omits the upload fields.
        A first upload (or a prior upload that failed ingest) returns `201`
        with the signed-URL fields.
      operationId: createAsset
      parameters:
        - $ref: '#/components/parameters/XProjectId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateAssetRequest'
            example:
              filename: q2-launch-deck.pdf
              mime_type: application/pdf
      responses:
        '200':
          description: |
            Content dedup hit. An asset with this `md5` already exists in the
            project; no upload is needed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateAssetResponse'
              example:
                asset_id: asset_d8aad64dib2c7m3ae7j1
                already_exists: true
                status: ready
        '201':
          description: Upload URL minted.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateAssetResponse'
              example:
                asset_id: asset_d8aad64dib2c7m3ae7j1
                already_exists: false
                upload_url: >-
                  https://storage.googleapis.com/storytell-assets/asset_d8aad64dib2c7m3ae7j1?X-Goog-Signature=...
                upload_method: PUT
                upload_headers:
                  Content-Type: application/pdf
                expires_at: '2026-05-23T10:30:00Z'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - apiKey: []
components:
  parameters:
    XProjectId:
      in: header
      name: X-Project-Id
      required: true
      schema:
        type: string
        pattern: ^project_[a-z0-9]{20}$
      example: project_d8a4td4dib27i4beefb0
      description: |
        Project identifier scoping the request. Required on every
        project-scoped public endpoint. Missing or malformed values respond
        with HTTP 400 and code `publicapi.tenancy.project.missing`.
  schemas:
    CreateAssetRequest:
      type: object
      required:
        - filename
        - mime_type
      properties:
        filename:
          type: string
          description: Original filename. Used for display and ingest hints.
        mime_type:
          type: string
          description: RFC 6838 media type of the upload.
        md5:
          type: string
          description: |
            Hex-encoded md5 of the file. Optional. When supplied and content
            with this digest already exists in the project, the server returns
            the existing asset instead of a new upload URL.
    CreateAssetResponse:
      type: object
      required:
        - asset_id
        - already_exists
      description: |
        Two shapes share this schema. A new upload (`201`) carries the
        signed-URL fields the client uses to PUT the bytes. A content-dedup hit
        (`200`) sets `already_exists` to true, reports the existing asset's
        `status`, and omits the upload fields.
      properties:
        asset_id:
          type: string
          pattern: ^asset_[a-z0-9]{20}$
        already_exists:
          type: boolean
          description: |
            True when an asset with the request's `md5` already existed; the
            upload fields are then absent.
        status:
          $ref: '#/components/schemas/AssetStatus'
        upload_url:
          type: string
          format: uri
        upload_method:
          type: string
          example: PUT
          description: |
            HTTP method to use for the upload. `PUT` today; resumable
            multi-part uploads may add new values without breaking the
            existing PUT flow.
        upload_headers:
          type: object
          additionalProperties:
            type: string
          description: |
            Headers the client MUST apply verbatim to the upload request.
            Includes `Content-Type`.
        expires_at:
          type: string
          format: date-time
    AssetStatus:
      type: string
      enum:
        - uploaded
        - ingesting
        - ready
        - failed
      description: |
        Asset lifecycle. Progresses uploaded -> ingesting -> ready, or
        terminates at failed on any extraction error.
    Error:
      type: object
      required:
        - code
        - statusCode
      properties:
        code:
          type: string
          pattern: ^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+$
          description: |
            Stable dotted, lowercase identifier, namespaced by domain and
            operation (`<domain>.<op>.<reason>`). Suitable for client-side
            i18n keys and analytics. Codes are additive; existing codes are
            never reworded.
          example: publicapi.auth.invalid
        humane:
          type: string
          description: Plain-English message safe to display to end users.
          example: The provided API key is invalid or has been revoked.
        statusCode:
          type: integer
          minimum: 400
          maximum: 599
          description: |
            Mirror of the HTTP status code. (Field name is camelCase here
            only — owned by `nutils.Error` across the platform.)
          example: 401
  responses:
    BadRequest:
      description: Malformed request, validation failure, or missing tenancy header.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            missingProject:
              summary: Missing X-Project-Id
              value:
                code: publicapi.tenancy.project.missing
                humane: X-Project-Id header is required.
                statusCode: 400
    Unauthorized:
      description: Missing, malformed, or revoked credentials.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            code: publicapi.auth.invalid
            humane: The provided API key is invalid or has been revoked.
            statusCode: 401
    InternalServerError:
      description: Unexpected server error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: X-API-Key
      description: |
        Personal Access Token, sent verbatim as `pat_<32 chars>`. PATs are
        minted from the Chief settings UI.

````