# Create a document (/reference/api/documents/create-document)

```json
[
  {
    "method": "POST",
    "path": "/api/v1/documents",
    "operationId": "createDocument",
    "tags": [
      "Documents"
    ],
    "summary": "Create a document",
    "description": "Adds a document from inline text, a public link or a finished upload. The document ID is the SHA-256 of the canonical file, so adding the same bytes again returns the same document. A DOCX returns `202` with an upload resource while it is converted.",
    "x-required-scope": "documents:write",
    "security": [
      {
        "oauth": [
          "documents:write"
        ]
      },
      {
        "sessionCookie": []
      },
      {
        "secureSessionCookie": []
      }
    ],
    "responses": {
      "201": {
        "description": "Canonical document registered. A PDF may still be processing.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Document"
            }
          }
        },
        "headers": {
          "Location": {
            "schema": {
              "type": "string"
            }
          }
        }
      },
      "202": {
        "description": "DOCX conversion pending. Observe events, then GET statusUrl to register the resulting PDF.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Upload"
            }
          }
        },
        "headers": {
          "Location": {
            "schema": {
              "type": "string"
            }
          }
        }
      },
      "429": {
        "description": "Compute admission or usage is limited.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        },
        "headers": {
          "Retry-After": {
            "description": "Seconds until retry.",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        }
      },
      "default": {
        "description": "Request failed. Inspect error.code and error.message.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "requestBody": {
      "required": true,
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/CreateDocument"
          },
          "examples": {
            "text": {
              "summary": "From text",
              "value": {
                "name": "notes.md",
                "source": {
                  "type": "text",
                  "text": "# Notes\n\nA document to read."
                }
              }
            },
            "url": {
              "summary": "From a link",
              "value": {
                "source": {
                  "type": "url",
                  "url": "https://example.com/article"
                }
              }
            },
            "upload": {
              "summary": "From an upload",
              "value": {
                "source": {
                  "type": "upload",
                  "uploadId": "0b9c6a1e-5d0f-4e7b-9a53-2f4c8f1f7d10"
                }
              }
            }
          }
        }
      }
    }
  }
]
```

## Components

```json
{
  "#/components/schemas/CreateDocument": {
    "type": "object",
    "properties": {
      "source": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "type": {
                "const": "text"
              },
              "text": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "type",
              "text"
            ]
          },
          {
            "type": "object",
            "properties": {
              "type": {
                "const": "url"
              },
              "url": {
                "type": "string",
                "format": "uri",
                "description": "A public link. A PDF, EPUB, DOCX, Markdown or text file is kept as that file, up to the upload limit; a web page becomes Markdown."
              }
            },
            "required": [
              "type",
              "url"
            ]
          },
          {
            "type": "object",
            "properties": {
              "type": {
                "const": "upload"
              },
              "uploadId": {
                "type": "string",
                "format": "uuid"
              }
            },
            "required": [
              "type",
              "uploadId"
            ]
          }
        ]
      },
      "name": {
        "type": "string"
      },
      "folderId": {
        "type": [
          "string",
          "null"
        ]
      },
      "author": {
        "type": "string"
      },
      "language": {
        "type": "string"
      }
    },
    "required": [
      "source"
    ]
  },
  "#/components/schemas/Document": {
    "allOf": [
      {
        "$ref": "#/components/schemas/DocumentMetadata"
      },
      {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "not_started",
              "processing",
              "ready",
              "failed",
              "unknown"
            ],
            "description": "not_started: a PDF has not been parsed yet and reading or generating will start it. unknown: the compute worker could not be reached; retry."
          },
          "operationId": {
            "type": [
              "string",
              "null"
            ]
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "webUrl": {
            "type": "string",
            "format": "uri"
          },
          "fileUrl": {
            "type": "string"
          }
        },
        "required": [
          "status",
          "operationId",
          "error",
          "webUrl",
          "fileUrl"
        ]
      }
    ]
  },
  "#/components/schemas/DocumentMetadata": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string",
        "pattern": "^[a-f0-9]{64}$"
      },
      "name": {
        "type": "string"
      },
      "size": {
        "type": "integer"
      },
      "lastModified": {
        "type": "number"
      },
      "type": {
        "type": "string",
        "enum": [
          "pdf",
          "epub",
          "docx",
          "html"
        ]
      },
      "scope": {
        "type": "string",
        "enum": [
          "user"
        ]
      },
      "folderId": {
        "type": "string"
      },
      "recentlyOpenedAt": {
        "type": "number"
      },
      "contentVersion": {
        "type": "string"
      },
      "author": {
        "type": "string"
      },
      "language": {
        "type": "string"
      },
      "readingProgress": {
        "type": "object",
        "properties": {
          "fraction": {
            "type": [
              "number",
              "null"
            ]
          },
          "updatedAtMs": {
            "type": "number"
          }
        },
        "required": [
          "fraction",
          "updatedAtMs"
        ]
      }
    },
    "required": [
      "id",
      "name",
      "size",
      "lastModified",
      "type"
    ]
  },
  "#/components/schemas/Error": {
    "type": "object",
    "properties": {
      "error": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "retryAfterMs": {
            "type": "number",
            "minimum": 0
          }
        },
        "required": [
          "code",
          "message"
        ]
      }
    },
    "required": [
      "error"
    ]
  },
  "#/components/schemas/Upload": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string",
        "format": "uuid"
      },
      "status": {
        "type": "string",
        "enum": [
          "pending",
          "processing",
          "ready",
          "failed"
        ]
      },
      "document": {
        "anyOf": [
          {
            "$ref": "#/components/schemas/Document"
          },
          {
            "type": "null"
          }
        ]
      },
      "operationId": {
        "type": [
          "string",
          "null"
        ]
      },
      "error": {
        "type": [
          "string",
          "null"
        ]
      },
      "statusUrl": {
        "type": "string"
      },
      "eventsUrl": {
        "type": [
          "string",
          "null"
        ]
      }
    },
    "required": [
      "id",
      "status",
      "document",
      "operationId",
      "error",
      "statusUrl",
      "eventsUrl"
    ]
  }
}
```