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

# Create Workspace Document

> Create or reuse a workspace document from an uploaded key.

Create a workspace document from a temporary upload key returned by `/vapor/signed-storage-url`.

If a document with identical content already exists in the same workspace, the API reuses it (`sha256` dedup).

## Authentication & Scope

Requires `documents-write`.

## Request

```http theme={null}
POST /workspaces/12/documents HTTP/1.1
Host: api.raydocs.com
Authorization: Bearer <token>
Content-Type: application/json

{
  "key": "tmp/721c7d17-f810-41a8-8c1c-a7e8cd2e52d0",
  "filename": "invoice.pdf"
}
```

## Response

`201 Created` when new, `200 OK` when reused.

```json theme={null}
{
  "document": {
    "id": "880e8400-e29b-41d4-a716-446655440000",
    "workspace_id": 12,
    "filename": "invoice.pdf",
    "sha256": "6de7f6f5894c9f3fd1f6f8a4d1b3115d0d9b4b19d7a8a661f9fe90f9c2d80c3b",
    "status": "uploaded"
  },
  "dedup": {
    "reused": true,
    "matched_by": "sha256"
  },
  "document_ref": {
    "kind": "documentRef",
    "documentId": "880e8400-e29b-41d4-a716-446655440000",
    "workspaceId": 12
  }
}
```


## OpenAPI

````yaml post /workspaces/{workspaceId}/documents
openapi: 3.0.1
info:
  title: Raydocs API
  description: REST API for document extraction with AI-powered data parsing
  version: 1.0.0
servers:
  - url: https://api.raydocs.com
security:
  - bearerAuth: []
tags:
  - name: Workspaces
    description: Create and manage workspaces.
  - name: Workspace Users
    description: Manage users within a workspace.
  - name: Extraction Templates
    description: Define extraction schemas and settings.
  - name: Extraction Sessions
    description: Manage extraction jobs and documents.
  - name: Batch Operations
    description: Bulk operations on sessions.
  - name: Documents
    description: Upload and manage source documents.
  - name: Results
    description: Access extraction results.
paths:
  /workspaces/{workspaceId}/documents:
    post:
      tags:
        - Documents
      summary: Create Workspace Document
      description: >-
        Create or reuse a workspace-scoped document from a temporary upload key.
        Requires `documents-write`.
      operationId: createWorkspaceDocument
      parameters:
        - name: workspaceId
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - key
              properties:
                key:
                  type: string
                  description: Temporary upload key from `/vapor/signed-storage-url`
                filename:
                  type: string
                mime:
                  type: string
      responses:
        '200':
          description: Reused existing document by content hash
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkspaceDocumentCreateResponse'
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkspaceDocumentCreateResponse'
        '403':
          description: Forbidden
        '422':
          description: Validation error
components:
  schemas:
    WorkspaceDocumentCreateResponse:
      type: object
      properties:
        document:
          $ref: '#/components/schemas/Document'
        dedup:
          type: object
          properties:
            reused:
              type: boolean
            matched_by:
              type: string
              nullable: true
        document_ref:
          $ref: '#/components/schemas/DocumentRef'
    Document:
      type: object
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
        workspace_id:
          type: integer
        filename:
          type: string
        mime:
          type: string
        size:
          type: integer
          description: File size in bytes
        sha256:
          type: string
          minLength: 64
          maxLength: 64
        status:
          type: string
          enum:
            - uploaded
            - queued
            - parsing
            - parsed
            - processed
            - failed
        source_type:
          type: string
          enum:
            - upload
            - url
            - connector
        source_url:
          type: string
          nullable: true
        parsings:
          type: array
          items:
            $ref: '#/components/schemas/DocumentParsingSummary'
        created_at:
          type: string
          format: date-time
          readOnly: true
    DocumentRef:
      type: object
      required:
        - kind
        - documentId
        - workspaceId
      properties:
        kind:
          type: string
          example: documentRef
        documentId:
          type: string
          format: uuid
        workspaceId:
          type: integer
        filename:
          type: string
        mime:
          type: string
        size:
          type: integer
        sha256:
          type: string
        source:
          type: object
          properties:
            type:
              type: string
              enum:
                - upload
                - url
                - connector
            url:
              type: string
              nullable: true
        createdAt:
          type: string
          format: date-time
    DocumentParsingSummary:
      type: object
      properties:
        id:
          type: string
          format: uuid
        config_hash:
          type: string
        status:
          type: string
          enum:
            - queued
            - processing
            - ready
            - failed
        parser_version:
          type: string
        updated_at:
          type: string
          format: date-time
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >
        Personal Access Token created from the Raydocs dashboard.

        Include in the Authorization header: `Bearer <your_token>`

        See [API Keys](/api-reference/api-keys) for token creation and
        management.

````