{
  "openapi": "3.1.0",
  "info": {
    "title": "Charta API",
    "version": "1.0.0",
    "description": "Send documents to Charta from your own tools, scripts or automation platforms (Zapier, Make, n8n). Authentication uses a team access key created in Charta under Settings › Integrations. Available on the Pro and Premium plans.",
    "contact": { "name": "Charta support", "email": "contact@chartahub.app", "url": "https://chartahub.app/developers" }
  },
  "servers": [{ "url": "https://chartahub.app/api/public/v1" }],
  "security": [{ "bearerAuth": [] }, { "apiKeyHeader": [] }],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Team access key, starting with chk_. Sent as: Authorization: Bearer chk_..."
      },
      "apiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key",
        "description": "Alternative to the Authorization header."
      }
    },
    "schemas": {
      "Me": {
        "type": "object",
        "properties": {
          "teamName": { "type": "string", "description": "Name of the Charta team that owns the key.", "example": "Durand SAS" },
          "keyName": { "type": "string", "description": "Label given to the key when it was created.", "example": "Zapier — supplier invoices" }
        },
        "required": ["teamName", "keyName"]
      },
      "DocumentCreated": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid", "description": "Identifier of the new document." },
          "fileName": { "type": "string", "example": "supplier-contract.pdf" },
          "status": { "type": "string", "enum": ["processing"], "description": "Text extraction, classification and summary run in the background." }
        },
        "required": ["id", "fileName", "status"]
      },
      "Error": {
        "type": "object",
        "properties": {
          "statusCode": { "type": "integer", "example": 401 },
          "message": { "type": "string", "example": "Clé API invalide" },
          "error": { "type": "string", "example": "Unauthorized" }
        }
      }
    },
    "responses": {
      "Unauthorized": { "description": "Missing, invalid or revoked key.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "Forbidden": { "description": "The team is not (or no longer) on a plan that includes API access.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "TooManyRequests": { "description": "More than 30 requests per minute from the same IP address." }
    }
  },
  "paths": {
    "/me": {
      "get": {
        "operationId": "getMe",
        "summary": "Check a key",
        "description": "Returns the team that owns the key. Creates nothing. Use it to test a connection.",
        "responses": {
          "200": { "description": "Valid key.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Me" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/TooManyRequests" }
        }
      }
    },
    "/documents": {
      "post": {
        "operationId": "createDocument",
        "summary": "Send a document",
        "description": "Adds a PDF to the team's documents. Send the file itself (multipart) or a public https link to it (JSON). The document is then processed like any import: text extraction, automatic classification and summary.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": { "type": "string", "format": "binary", "description": "The PDF. 20 MB max." },
                  "fileName": { "type": "string", "description": "Optional. Name shown in Charta (.pdf is added if missing)." },
                  "note": { "type": "string", "maxLength": 5000, "description": "Optional. Context note attached to the document." }
                },
                "required": ["file"]
              }
            },
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "fileUrl": { "type": "string", "format": "uri", "description": "Public https link to the PDF. Charta downloads it (20 MB max, 20 s timeout). Links to private or internal network addresses are refused." },
                  "fileName": { "type": "string" },
                  "note": { "type": "string", "maxLength": 5000 }
                },
                "required": ["fileUrl"]
              }
            }
          }
        },
        "responses": {
          "201": { "description": "Document created.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/DocumentCreated" } } } },
          "400": { "description": "No file, not a valid PDF, link not https or not public, or download failed.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "413": { "description": "File larger than 20 MB." },
          "429": { "$ref": "#/components/responses/TooManyRequests" }
        }
      }
    }
  }
}
