# Create an organization with its first product (/api/organizations/create_organization)

`POST /v1/organizations`

Operation name: `create_organization`

For a person setting up Heuristic for a new company; to add a product to an existing organization use `create_product`. The person becomes the organization's Admin. It also starts reading the product's knowledge base (its public documentation site): `meta.ingestionRun` is that knowledge base read, or null when it could not start (then start it with `start_knowledge_base_read`). The read takes minutes: check `get_knowledge_base_read` every 30 seconds; it is done when its status is completed, failed or stopped. Not safe to retry: each call creates another organization.

## Authentication

An OAuth access token for the person who allowed your tool: register a client, then the authorization code flow with PKCE (S256). Send it as `Authorization: Bearer <token>` on every route that needs a signed-in person. Calls with a token are limited per person, across all their apps, to 120 calls a minute and 10,000 a UTC day; calls that start AI runs or knowledge base reads (creating an organization, starting a knowledge base read, rebuilding categories, retrying topics or rechecking) also to 10 a minute and 200 a UTC day. Over a limit a call answers 429 `rate_limited` with `Retry-After` and `details.retryAfter` in seconds, and changes nothing.

## Request body

Content type: `application/json` (required)

```json
{
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 100,
      "description": "The organization's name, usually the company's, 1 to 100 characters."
    },
    "product": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100,
          "pattern": "^[^\\u0000-\\u001f\\u007f-\\u009f\\u2028\\u2029]*$",
          "description": "The product's name, 1 to 100 characters, on one line."
        },
        "knowledgeBaseUrl": {
          "type": "string",
          "maxLength": 2048,
          "pattern": "^[^\\s\\u0000-\\u001f\\u007f-\\u009f]+$",
          "description": "The product's public documentation site, an http or https address such as https://docs.example.com; never a local or private address. Heuristic reads it to find the product's features."
        },
        "description": {
          "type": "string",
          "maxLength": 500,
          "pattern": "^[^\\u0000-\\u0008\\u000b\\u000c\\u000e-\\u001f\\u007f-\\u009f\\u2028\\u2029]*$",
          "default": "",
          "description": "What the product is, up to 500 characters. Empty when left out."
        }
      },
      "required": [
        "name",
        "knowledgeBaseUrl"
      ],
      "description": "Its first product."
    }
  },
  "required": [
    "name",
    "product"
  ],
  "description": "The organization and its first product."
}
```

## Responses

### 201

The new organization and product

```json
{
  "type": "object",
  "properties": {
    "data": {
      "type": "object",
      "properties": {
        "organization": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "role": {
              "type": "string",
              "enum": [
                "admin",
                "user"
              ]
            },
            "reportingCurrency": {
              "type": "string"
            },
            "createdAt": {
              "type": "string"
            },
            "allowKeysWithoutExpiry": {
              "type": "boolean"
            }
          },
          "required": [
            "id",
            "name",
            "role",
            "reportingCurrency",
            "createdAt"
          ]
        },
        "product": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "organizationId": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "knowledgeBaseUrl": {
              "type": "string"
            },
            "access": {
              "type": "string",
              "enum": [
                "owner",
                "viewer"
              ]
            },
            "createdAt": {
              "type": "string"
            },
            "archivedAt": {
              "type": [
                "string",
                "null"
              ],
              "deprecated": true,
              "description": "Deprecated: use `deletedAt` and `restorableUntil` instead. It may be removed from 2026-12-10."
            },
            "deletedAt": {
              "type": [
                "string",
                "null"
              ],
              "description": "When it was deleted; null while active."
            },
            "restorableUntil": {
              "type": [
                "string",
                "null"
              ],
              "description": "Until when it can be restored, 30 days after `deletedAt`; then removed for good. Null while active."
            }
          },
          "required": [
            "id",
            "organizationId",
            "name",
            "description",
            "knowledgeBaseUrl",
            "access",
            "createdAt",
            "archivedAt",
            "deletedAt",
            "restorableUntil"
          ]
        }
      },
      "required": [
        "organization",
        "product"
      ]
    },
    "meta": {
      "type": "object",
      "properties": {
        "ingestionRun": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "id": {
              "type": "string"
            },
            "productId": {
              "type": "string"
            },
            "status": {
              "type": "string",
              "enum": [
                "queued",
                "starting",
                "processing",
                "completed",
                "failed",
                "stopped"
              ]
            },
            "url": {
              "type": "string"
            },
            "pagesProcessed": {
              "type": "integer"
            },
            "featuresExtracted": {
              "type": "integer"
            },
            "pagesFailed": {
              "type": "integer"
            },
            "pagesTooLong": {
              "type": "integer"
            },
            "categoriesUnnamed": {
              "type": "integer"
            },
            "failure": {
              "type": [
                "object",
                "null"
              ],
              "properties": {
                "code": {
                  "type": "string",
                  "enum": [
                    "crawl_unavailable",
                    "crawl_stopped",
                    "no_pages",
                    "ai_unavailable",
                    "grouping_failed",
                    "grouping_unavailable",
                    "naming_unavailable"
                  ]
                },
                "message": {
                  "type": "string"
                }
              },
              "required": [
                "code",
                "message"
              ]
            },
            "changes": {
              "type": [
                "object",
                "null"
              ],
              "properties": {
                "newFeatures": {
                  "type": "integer"
                },
                "updatedFeatures": {
                  "type": "integer"
                },
                "pagesRemoved": {
                  "type": [
                    "integer",
                    "null"
                  ]
                }
              },
              "required": [
                "newFeatures",
                "updatedFeatures",
                "pagesRemoved"
              ]
            },
            "startedAutomatically": {
              "type": "boolean"
            },
            "startedBy": {
              "type": [
                "object",
                "null"
              ],
              "properties": {
                "name": {
                  "type": "string"
                },
                "email": {
                  "type": "string"
                }
              },
              "required": [
                "name",
                "email"
              ]
            },
            "stoppedBy": {
              "type": [
                "object",
                "null"
              ],
              "properties": {
                "name": {
                  "type": "string"
                },
                "email": {
                  "type": "string"
                }
              },
              "required": [
                "name",
                "email"
              ]
            },
            "createdAt": {
              "type": "string"
            },
            "finishedAt": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          "required": [
            "id",
            "productId",
            "status",
            "url",
            "pagesProcessed",
            "featuresExtracted",
            "pagesFailed",
            "pagesTooLong",
            "categoriesUnnamed",
            "failure",
            "changes",
            "startedAutomatically",
            "startedBy",
            "stoppedBy",
            "createdAt",
            "finishedAt"
          ]
        }
      },
      "required": [
        "ingestionRun"
      ]
    }
  },
  "required": [
    "data",
    "meta"
  ]
}
```

### 400

Error

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "details": {}
      },
      "required": [
        "code",
        "message"
      ]
    }
  },
  "required": [
    "error"
  ]
}
```

### 401

Error

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "details": {}
      },
      "required": [
        "code",
        "message"
      ]
    }
  },
  "required": [
    "error"
  ]
}
```

### 403

Error

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "details": {}
      },
      "required": [
        "code",
        "message"
      ]
    }
  },
  "required": [
    "error"
  ]
}
```

### 413

Error

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "details": {}
      },
      "required": [
        "code",
        "message"
      ]
    }
  },
  "required": [
    "error"
  ]
}
```

## Example request

```bash
curl -X POST "https://staging.heuristic.app/v1/organizations" \
  -H "Authorization: Bearer <access token>" \
  -H "Content-Type: application/json" \
  -d '{"name":"string","product":{"name":"string","knowledgeBaseUrl":"string","description":""}}'
```
