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

# Create File Context

> Create a new file context (upload pipeline). Contexts define the rules applied to every file uploaded under them — allowed extensions, size limits, blank/corrupt rejection, virus scanning, rate limits, and storage quotas.



## OpenAPI

````yaml POST /api/v1/contexts
openapi: 3.0.3
info:
  title: Uplint API
  version: 0.1.0
  description: >-
    Uplint is a file safety and integrity platform. Upload files through
    context-aware pipelines that automatically validate integrity, detect blank
    or placeholder content, and scan for viruses — all behind a single API.


    This specification covers the core Uplint REST API:


    - **API Keys** — Create and manage scoped API keys for programmatic access.

    - **File Contexts** — Define upload pipelines with per-context rules
    (allowed extensions, size limits, blank/corrupt rejection, virus scanning,
    rate limits, and storage quotas).

    - **Files** — Upload, list, download, inspect, and delete files. Every
    upload runs through the validation pipeline configured on its context.


    All endpoints are tenant-scoped. Authenticate with an API key or JWT token
    via the `Authorization` header.
  contact:
    name: Uplint Team
    url: https://uplint.dev
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT
servers:
  - url: https://api.uplint.dev
    description: Production
  - url: http://localhost:8000
    description: Local development
security:
  - BearerAuth: []
tags:
  - name: API Keys
    description: >-
      Create, list, inspect, update, and revoke API keys. Each key carries
      scoped permissions (`upload`, `download`, `metadata`, `delete`, `admin`)
      and is bound to the authenticated tenant.
  - name: File Contexts
    description: >-
      File contexts define upload pipelines. Each context specifies allowed
      extensions, max file size, whether to reject blank or corrupt files, virus
      scanning, rate limits, and storage quotas. Files are always uploaded into
      a context.
  - name: Files
    description: >-
      Upload, list, download, inspect metadata, and delete files. Every upload
      is validated against its context rules before storage.
  - name: Storage Buckets
    description: >-
      Manage the S3 buckets a tenant stores files in. Each tenant can register
      multiple buckets (bring-your-own S3 credentials); one is the **default**
      (fallback) bucket, and file contexts can be routed to any active bucket.
      All storage endpoints require an `admin`-scoped API key.
paths:
  /api/v1/contexts:
    post:
      tags:
        - File Contexts
      summary: Create file context
      description: >-
        Create a new file context (upload pipeline). Contexts define the rules
        applied to every file uploaded under them — allowed extensions, size
        limits, blank/corrupt rejection, virus scanning, rate limits, and
        storage quotas.
      operationId: createFileContext
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateContextRequest'
            example:
              context_key: patient_reports
              display_name: Patient Reports
              description: Medical reports uploaded by patients
              allowed_extensions:
                - pdf
                - png
                - jpg
                - jpeg
              max_file_size_mb: 25
              reject_blank_files: true
              reject_corrupt_files: true
              scan_for_viruses: true
              upload_rate_limit:
                max_uploads: 100
                window_seconds: 60
              storage_quota_mb: 10240
      responses:
        '201':
          description: File context created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SuccessResponse_Context'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '409':
          description: A context with this `context_key` already exists.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          $ref: '#/components/responses/ValidationError'
      security:
        - BearerAuth: []
components:
  schemas:
    CreateContextRequest:
      type: object
      required:
        - context_key
        - display_name
      properties:
        context_key:
          type: string
          minLength: 1
          maxLength: 100
          pattern: ^[a-z][a-z0-9_]*$
          description: Unique, immutable identifier in snake_case.
        display_name:
          type: string
          minLength: 1
          maxLength: 255
          description: Human-readable name.
        description:
          type: string
          maxLength: 1000
          nullable: true
        allowed_extensions:
          type: array
          items:
            type: string
          default: []
          description: >-
            Allowed file extensions (e.g. `["pdf", "png"]`). Empty array allows
            all.
        max_file_size_mb:
          type: integer
          minimum: 1
          maximum: 500
          default: 10
          description: Maximum file size in megabytes.
        storage_path_template:
          type: string
          maxLength: 500
          nullable: true
          description: Custom S3 path template for uploaded files.
        reject_blank_files:
          type: boolean
          default: true
          description: Reject files detected as blank or placeholder content.
        reject_corrupt_files:
          type: boolean
          default: true
          description: Reject files that fail integrity checks.
        scan_for_viruses:
          type: boolean
          default: true
          description: Scan files for malware using ClamAV.
        upload_rate_limit:
          nullable: true
          description: Optional per-context upload rate limit.
          allOf:
            - $ref: '#/components/schemas/UploadRateLimitConfig'
        storage_quota_mb:
          type: integer
          minimum: 1
          maximum: 10485760
          nullable: true
          description: Storage quota in MB. `null` means unlimited.
        metadata:
          type: object
          additionalProperties: true
          nullable: true
        storage_config_id:
          type: string
          nullable: true
          description: >-
            ID of the storage bucket (`config_id`) this context routes uploads
            to. `null` uses the tenant's default bucket.
          example: cfg_a1b2c3d4e5f6
    SuccessResponse_Context:
      type: object
      properties:
        status:
          type: string
          enum:
            - SUCCESS
        message:
          type: string
        data:
          $ref: '#/components/schemas/ContextResponse'
        timestamp:
          type: string
          format: date-time
    ErrorResponse:
      type: object
      properties:
        status:
          type: string
          enum:
            - ERROR
        message:
          type: string
        errors:
          type: array
          items:
            type: string
        timestamp:
          type: string
          format: date-time
    UploadRateLimitConfig:
      type: object
      required:
        - max_uploads
        - window_seconds
      properties:
        max_uploads:
          type: integer
          minimum: 1
          maximum: 10000
          description: Maximum number of uploads allowed within the time window.
        window_seconds:
          type: integer
          minimum: 1
          maximum: 3600
          description: Time window in seconds.
    ContextResponse:
      type: object
      properties:
        context_id:
          type: string
        context_key:
          type: string
        tenant_id:
          type: string
        display_name:
          type: string
        description:
          type: string
          nullable: true
        allowed_extensions:
          type: array
          items:
            type: string
        max_file_size_mb:
          type: integer
        storage_path_template:
          type: string
        reject_blank_files:
          type: boolean
        reject_corrupt_files:
          type: boolean
        scan_for_viruses:
          type: boolean
        upload_rate_limit:
          nullable: true
          allOf:
            - $ref: '#/components/schemas/UploadRateLimitConfig'
        storage_quota_mb:
          type: integer
          nullable: true
        storage_used_bytes:
          type: integer
          nullable: true
        status:
          $ref: '#/components/schemas/FileContextStatus'
        metadata:
          type: object
          additionalProperties: true
        storage_config_id:
          type: string
          nullable: true
          description: >-
            ID of the storage bucket (`config_id`) this context routes uploads
            to. `null` uses the tenant's default bucket.
    FileContextStatus:
      type: string
      enum:
        - active
        - inactive
  responses:
    Unauthorized:
      description: Missing, invalid, or expired authentication credentials.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            status: ERROR
            message: Invalid or missing API key
            errors:
              - Authentication required
            timestamp: '2026-02-10T12:00:00Z'
    ValidationError:
      description: Request body failed validation.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            status: ERROR
            message: Validation error
            errors:
              - 'name: field required'
            timestamp: '2026-02-10T12:00:00Z'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Pass an API key or JWT token. API keys can be sent as `Authorization:
        Bearer <key>` or `Authorization: <key>`.

````