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

# Create a relationship definition

> Creates a new relationship definition between two object types



## OpenAPI

````yaml post /v1/relationships
openapi: 3.0.0
info:
  description: >-
    REST API for accessing and managing your Nex data. Generate API keys from
    the Nex web UI and use them to authenticate requests.
  title: Nex Developer API
  contact: {}
  version: '1.0'
servers:
  - url: https://app.nex.ai/api/developers
security: []
paths:
  /v1/relationships:
    post:
      tags:
        - Relationships
      summary: Create a relationship definition
      description: Creates a new relationship definition between two object types
      operationId: createRelationshipDefinition
      requestBody:
        content:
          application/json:
            schema:
              $ref: >-
                #/components/schemas/developer.CreateRelationshipDefinitionRequest
        description: Relationship definition to create
        required: true
      responses:
        '200':
          description: Created relationship definition
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/developer.RelationshipDefinitionResponse'
        '400':
          description: Bad request - Invalid data
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/httpx.APIError'
        '401':
          description: Unauthorized - Invalid or missing API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/httpx.APIError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/httpx.APIError'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    developer.CreateRelationshipDefinitionRequest:
      type: object
      required:
        - type
        - entity_definition_1_id
        - entity_definition_2_id
      properties:
        type:
          type: string
          description: Relationship cardinality
          enum:
            - one_to_one
            - one_to_many
            - many_to_many
        entity_definition_1_id:
          type: string
          description: First object definition ID
        entity_definition_2_id:
          type: string
          description: Second object definition ID
        entity_1_to_2_predicate:
          type: string
          description: Label for 1→2 direction (e.g., 'has')
        entity_2_to_1_predicate:
          type: string
          description: Label for 2→1 direction (e.g., 'belongs to')
      example:
        type: one_to_many
        entity_definition_1_id: '123'
        entity_definition_2_id: '456'
        entity_1_to_2_predicate: has
        entity_2_to_1_predicate: belongs to
    developer.RelationshipDefinitionResponse:
      type: object
      properties:
        id:
          type: string
        type:
          type: string
          enum:
            - one_to_one
            - one_to_many
            - many_to_many
        entity_definition_1_id:
          type: string
        entity_definition_2_id:
          type: string
        entity_1_to_2_predicate:
          type: string
        entity_2_to_1_predicate:
          type: string
        created_at:
          type: string
          format: date-time
      example:
        id: '789'
        type: one_to_many
        entity_definition_1_id: '123'
        entity_definition_2_id: '456'
        entity_1_to_2_predicate: has
        entity_2_to_1_predicate: belongs to
        created_at: '2024-01-15T10:00:00Z'
    httpx.APIError:
      type: object
      properties:
        code:
          type: integer
        message:
          type: string
  securitySchemes:
    ApiKeyAuth:
      description: 'API key for authentication (format: "Bearer YOUR_API_KEY")'
      type: apiKey
      name: Authorization
      in: header

````