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

# Create a file

> Registers a file and returns its link plus a presigned `upload_url`. PUT the file body to `upload_url` with the same `Content-Type` as `mime_type`; the link serves the file once the upload finishes.



## OpenAPI

````yaml /api-reference/openapi.generated.json post /api/files
openapi: 3.1.0
info:
  title: Empirical API
  version: 1.0.0
  description: Programmatic access to Empirical test runs, snoozes, and more.
  contact:
    name: Empirical
    url: https://empirical.run
servers:
  - url: https://api.empirical.run
security:
  - Bearer: []
tags:
  - name: Test Runs
    description: Trigger, list, and inspect end-to-end test runs.
  - name: Test Cases
    description: >-
      Browse the Playwright test cases synced from a project's repository and
      manage their tags.
  - name: Environments
    description: >-
      Named deployment targets (slug + Playwright project filters) a project's
      tests run against.
  - name: Snoozes
    description: Temporarily suppress known test failures for specific Playwright tests.
  - name: Analytics
    description: Aggregated test-run, test-count and test-case analytics for a project.
  - name: Badges
    description: Public README status badge images (SVG) for project environments.
  - name: Failure Groups
    description: >-
      Durable, cross-run identities for failure modes, carrying the latest
      triage diagnosis.
  - name: Files
    description: >-
      Upload files of any type and get a link to use in tasks, sessions and
      messages. Agents should use the `upload_file` tool, which returns a
      project-wide `file@<id>` handle (`<id>` is the file `id` below).
  - name: Reporter Configuration
    description: Reporters a project can use in environment and run reporter configs.
paths:
  /api/files:
    post:
      tags:
        - Files
      summary: Create a file
      description: >-
        Registers a file and returns its link plus a presigned `upload_url`. PUT
        the file body to `upload_url` with the same `Content-Type` as
        `mime_type`; the link serves the file once the upload finishes.
      operationId: createFile
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateFileRequest'
      responses:
        '200':
          description: The created file.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateFileResponse'
        '400':
          description: Invalid request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    CreateFileRequest:
      type: object
      properties:
        name:
          type: string
          minLength: 1
          description: File name.
        mime_type:
          type: string
          minLength: 1
          default: application/octet-stream
          description: MIME type. The upload must send the same `Content-Type` header.
        size_bytes:
          type: integer
          minimum: 0
          description: File size in bytes.
        origin_tool_call_id:
          type: string
          minLength: 1
          description: >-
            Tool call that produced the file, when an agent uploads it. The chat
            session is taken from the caller's credentials.
      required:
        - name
    CreateFileResponse:
      type: object
      properties:
        data:
          type: object
          properties:
            file:
              $ref: '#/components/schemas/File'
            upload_url:
              type: string
              description: >-
                Presigned PUT URL, valid for 1 hour. Send the file body with the
                same `Content-Type` as `mime_type`.
          required:
            - file
            - upload_url
          description: Response payload.
      required:
        - data
    ErrorResponse:
      type: object
      properties:
        data:
          nullable: true
          description: Always null for error responses.
        error:
          type: object
          properties:
            message:
              type: string
              description: Human-readable error message.
          required:
            - message
          description: Error details.
      required:
        - data
        - error
    File:
      type: object
      properties:
        id:
          type: integer
          description: File ID.
        name:
          type: string
          description: Stored file name.
        url:
          type: string
          description: Link to the file.
        mime_type:
          type: string
          nullable: true
          description: MIME type.
        size_bytes:
          type: number
          nullable: true
          description: File size in bytes, when known.
        status:
          type: string
          enum:
            - pending
            - uploaded
          description: >-
            `pending` until the upload to `upload_url` is confirmed with `PATCH
            /api/files/{id}`.
        origin_chat_session_id:
          type: integer
          nullable: true
          description: Chat session the file came from, if an agent created it.
        origin_tool_call_id:
          type: string
          nullable: true
          description: Tool call that produced the file, when known.
        created_at:
          type: string
          description: ISO 8601 creation time.
      required:
        - id
        - name
        - url
        - mime_type
        - size_bytes
        - status
        - origin_chat_session_id
        - origin_tool_call_id
        - created_at
  securitySchemes:
    Bearer:
      type: http
      scheme: bearer

````

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