---
title: "Download a package's classes as an ontology file a collection takes as its own"
method: GET
path: "/api/v0/graph-packages/{slug}/{version}/ontology"
tags: ["Knowledge Base Graph"]
---

# Download a package's classes as an ontology file a collection takes as its own

`GET /api/v0/graph-packages/{slug}/{version}/ontology`

## Request

- Base URL: `https://api.outerport.com` (the document declares no server; this is the origin it was published from)
- URL: `https://api.outerport.com/api/v0/graph-packages/{slug}/{version}/ontology`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/outerport/apis/outerport-api/docs/api/v0/graph-packages/:slug/:version/ontology/get.ts> (a function with typed inputs; its response is checked against the schema)

The package's classes and relationships, in the caller's language, as the entity_types and relationship_types POST /{kb_id}/graph/ontology takes, with no packages key: applied to a collection, they become its own classes, which it edits freely. Applied to a collection that subscribes to the same package, each class is that collection's edited version of the package's instead.

## Path parameters

- `slug` string, required
- `version` string, required

## Response `200`

Successful Response

- OntologyDocumentOutput: The ontology file. Unknown keys are refused so a misspelt section is an error, not a no-op.
  - `format` 'outerport.kg-ontology'
  - `format_version` 1
  - `collection_name` string
  - `packages` OntologyPackageOutput[], nullable
    - `slug` string, required
    - `version` string, required
    - `display_name` string
    - `entity_types` OntologyPackageEntityTypeOutput[]
      - `type_id` string, required
      - `display_name` string, required
      - `description` string, required
      - `tier` 'representation' | 'domain', required
      - `attribute_fields` AttributeFieldSpec[]
        - `name` string, required
        - `kind` string, required
        - `required` boolean
        - `description` string
        - `enum_values` string[], nullable
        - `label` string, nullable
        - `instant` boolean: Whether the field holds an ISO-8601 date or time a reader may order records by: always for a date or datetime field, and for a text field its type declares holds one.
      - `derived_properties` DerivedPropertyDefOutput[]
        - `id` string, required
        - `description` string
        - `rule` union, required
          - PatternMapRule: Derive a value from one stored field on the same entity: the field's text is matched (case-insensitive ``re.search``) against ``cases`` in order; misses fall back to ``default``. ``source_field`` is ``"name"`` or a stored-attribute id, never another derived property.
            - `kind` 'pattern_map'
            - `source_field` string
            - `cases` PatternCase[], required
              - …
            - `default` string, nullable
          - EdgeDegreeRule: Derive the count of the entity's own incident edges of one relationship type. ``node_role`` picks which end the entity sits on (``source`` = outgoing, ``target`` = incoming, ``either`` = both).
            - `kind` 'edge_degree'
            - `relationship_type_id` string, required
            - `node_role` 'source' | 'target' | 'either'
            - `minimum` integer: How many of these edges the ontology requires an instance to have. Zero means optional: an instance with none is complete, and no reader may present it as missing anything. This is the cardinality constraint — a count on its own is a measurement, and deciding after the fact that a zero looks wrong because other instances have more is a guess about the corpus rather than a statement of the ontology.
        - `label` string, nullable
    - `relationship_types` OntologyPackageRelationshipType[]
      - `type_id` string, required
      - `display_name` string, required
      - `description` string, required
      - `source_tier` 'representation' | 'domain', required
      - `target_tier` 'representation' | 'domain', required
      - `source_entity_type_ids` string[]
      - `target_entity_type_ids` string[]
      - `attribute_fields` AttributeFieldSpec[]
        - `name` string, required
        - `kind` string, required
        - `required` boolean
        - `description` string
        - `enum_values` string[], nullable
        - `label` string, nullable
        - `instant` boolean: Whether the field holds an ISO-8601 date or time a reader may order records by: always for a date or datetime field, and for a text field its type declares holds one.
      - `symmetric` boolean
  - `entity_types` EntityTypeUpsertRequestOutput[]
    - `type_id` string, required
    - `display_name` string, required
    - `description` string
    - `tier` 'representation' | 'domain', required
    - `attribute_fields` AttributeFieldSpec[]
      - `name` string, required
      - `kind` string, required
      - `required` boolean
      - `description` string
      - `enum_values` string[], nullable
      - `label` string, nullable
      - `instant` boolean: Whether the field holds an ISO-8601 date or time a reader may order records by: always for a date or datetime field, and for a text field its type declares holds one.
    - `derived_properties` DerivedPropertyDefOutput[]
      - `id` string, required
      - `description` string
      - `rule` union, required
        - PatternMapRule: Derive a value from one stored field on the same entity: the field's text is matched (case-insensitive ``re.search``) against ``cases`` in order; misses fall back to ``default``. ``source_field`` is ``"name"`` or a stored-attribute id, never another derived property.
          - `kind` 'pattern_map'
          - `source_field` string
          - `cases` PatternCase[], required
            - `pattern` string, required
            - `value` string, required
          - `default` string, nullable
        - EdgeDegreeRule: Derive the count of the entity's own incident edges of one relationship type. ``node_role`` picks which end the entity sits on (``source`` = outgoing, ``target`` = incoming, ``either`` = both).
          - `kind` 'edge_degree'
          - `relationship_type_id` string, required
          - `node_role` 'source' | 'target' | 'either'
          - `minimum` integer: How many of these edges the ontology requires an instance to have. Zero means optional: an instance with none is complete, and no reader may present it as missing anything. This is the cardinality constraint — a count on its own is a measurement, and deciding after the fact that a zero looks wrong because other instances have more is a guess about the corpus rather than a statement of the ontology.
      - `label` string, nullable
    - `source_bindings` SourceBindingSpec[]
      - `source_kind` string, required: A source in the source schema catalog, e.g. email.
      - `role` string, required: A class role or link role that source offers.
      - `field_map` object: Attribute of the class -> field of the role that fills it. A relationship's binding maps nothing.
  - `relationship_types` RelationshipTypeUpsertRequest[]
    - `type_id` string, required
    - `display_name` string, required
    - `description` string
    - `source_tier` 'representation' | 'domain', required
    - `target_tier` 'representation' | 'domain', required
    - `attribute_fields` AttributeFieldSpec[]
      - `name` string, required
      - `kind` string, required
      - `required` boolean
      - `description` string
      - `enum_values` string[], nullable
      - `label` string, nullable
      - `instant` boolean: Whether the field holds an ISO-8601 date or time a reader may order records by: always for a date or datetime field, and for a text field its type declares holds one.
    - `source_bindings` SourceBindingSpec[]
      - `source_kind` string, required: A source in the source schema catalog, e.g. email.
      - `role` string, required: A class role or link role that source offers.
      - `field_map` object: Attribute of the class -> field of the role that fills it. A relationship's binding maps nothing.
    - `symmetric` boolean: The relationship has no direction, such as two items joined by a pipe. An edited package relationship keeps the package's setting.

## Other responses

- `422`: Validation Error

## Changes

- **2026-11-09** `ecd5b922e78a`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/outerport/apis/outerport-api/changes/api/v0/graph-packages/:slug/:version/ontology/get.md)

---

[API](https://skmtc.dev/outerport/apis/outerport-api.md) - [All operations](https://skmtc.dev/outerport/apis/outerport-api/llms.txt) - [OpenAPI document](https://skmtc.dev/outerport/apis/outerport-api/revisions/08b5bf6f7f18?raw)
