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

# Create Ontology

> Save an ontology in Intellibase and generate an ontology ID which can then be used to create a project with this ontology

## Endpoint

```
POST https://api.intellibase.dev/api/v1/ontologies
```

## Authentication

Requires a valid API key.

## Request Body

<ParamField body="name" type="string" required>
  Descriptive name for the ontology (e.g., "Software Engineering", "Customer Support")
</ParamField>

<ParamField body="schema" type="object" required>
  Ontology schema definition including hierarchy and edge types

  <Expandable title="Schema Structure">
    <ParamField body="schema.ontology" type="object">
      <ParamField body="schema.ontology.hierarchy" type="array">
        Array of hierarchy levels (0 = concrete, higher = abstract)
      </ParamField>

      <ParamField body="schema.ontology.edge_types" type="array">
        Array of valid relationship types
      </ParamField>
    </ParamField>
  </Expandable>
</ParamField>

## Response

<ResponseField name="id" type="string">
  Unique identifier for the ontology
</ResponseField>

<ResponseField name="name" type="string">
  The ontology name
</ResponseField>

<ResponseField name="created_at" type="string" format="datetime">
  When the ontology was created
</ResponseField>

<ResponseField name="schema" type="object">
  The complete ontology schema
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.intellibase.dev/api/v1/ontologies \
    -H "Authorization: Bearer ib-your-api-key" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Software Engineering",
      "schema": {
        "ontology": {
          "hierarchy": [
            {
              "level": 0,
              "node_types": {
                "Developer": {
                  "properties": ["name", "role", "team"],
                  "description": "Software developer"
                },
                "Feature": {
                  "properties": ["name", "status", "deadline"],
                  "description": "Software feature"
                }
              }
            }
          ],
          "edge_types": [
            {
              "name": "WORKS_ON",
              "source_types": ["Developer"],
              "target_types": ["Feature"],
              "properties": ["role"],
              "temporal": true,
              "description": "Developer works on feature"
            }
          ]
        }
      }
    }'
  ```

  ```python Python theme={null}
  import requests

  ontology_schema = {
      "name": "Software Engineering",
      "schema": {
          "ontology": {
              "hierarchy": [
                  {
                      "level": 0,
                      "node_types": {
                          "Developer": {
                              "properties": ["name", "role", "team"],
                              "description": "Software developer"
                          },
                          "Feature": {
                              "properties": ["name", "status", "deadline"],
                              "description": "Software feature"
                          }
                      }
                  }
              ],
              "edge_types": [
                  {
                      "name": "WORKS_ON",
                      "source_types": ["Developer"],
                      "target_types": ["Feature"],
                      "properties": ["role"],
                      "temporal": True,
                      "description": "Developer works on feature"
                  }
              ]
          }
      }
  }

  response = requests.post(
      "https://api.intellibase.dev/api/v1/ontologies",
      headers={
          "Authorization": "Bearer ib-your-api-key",
          "Content-Type": "application/json"
      },
      json=ontology_schema
  )

  ontology = response.json()
  print(f"Created ontology: {ontology['id']}")
  ```

  ```typescript TypeScript theme={null}
  const ontologySchema = {
    name: "Software Engineering",
    schema: {
      ontology: {
        hierarchy: [
          {
            level: 0,
            node_types: {
              Developer: {
                properties: ["name", "role", "team"],
                description: "Software developer"
              },
              Feature: {
                properties: ["name", "status", "deadline"],
                description: "Software feature"
              }
            }
          }
        ],
        edge_types: [
          {
            name: "WORKS_ON",
            source_types: ["Developer"],
            target_types: ["Feature"],
            properties: ["role"],
            temporal: true,
            description: "Developer works on feature"
          }
        ]
      }
    }
  };

  const response = await fetch(
    "https://api.intellibase.dev/api/v1/ontologies",
    {
      method: "POST",
      headers: {
        "Authorization": "Bearer ib-your-api-key",
        "Content-Type": "application/json"
      },
      body: JSON.stringify(ontologySchema)
    }
  );

  const ontology = await response.json();
  console.log(`Created ontology: ${ontology.id}`);
  ```
</RequestExample>

<ResponseExample>
  ```json 201 Created theme={null}
  {
    "id": "ont-abc123",
    "name": "Software Engineering",
    "created_at": "2024-01-15T10:30:00Z",
    "schema": {
      "ontology": {
        "hierarchy": [ ... ],
        "edge_types": [ ... ]
      }
    }
  }
  ```

  ```json 400 Bad Request theme={null}
  {
    "detail": "Invalid ontology schema: missing hierarchy definition"
  }
  ```

  ```json 401 Unauthorized theme={null}
  {
    "detail": "Invalid API key"
  }
  ```
</ResponseExample>

<Tip>
  Use the [Suggest Ontology](/api-reference/ontologies/suggest) endpoint to get an AI-generated starting point!
</Tip>
