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

# Generate triples

> Use OpenAI to extract knowledge triples from natural language. Supports web search for real-time information. Streams responses by default, use format=json for non-streaming.



## OpenAPI

````yaml api-reference/openapi.json post /api/triples/generate
openapi: 3.1.0
info:
  title: Neode API
  description: >-
    A knowledge graph API for storing, querying, and generating triples. Use
    Neode as a triples store for your LLM applications - store facts, query
    knowledge, and generate new triples from any context.
  version: 1.0.0
  contact:
    name: Neode
servers:
  - url: https://www.neode.ai
    description: Production server
  - url: http://localhost:5173
    description: Local development
security:
  - BearerAuth: []
tags:
  - name: Search
    description: Semantic search across your knowledge graph
  - name: Triples
    description: Store and query knowledge as subject-predicate-object triples
  - name: Entities
    description: Manage entities (subjects and objects) with automatic disambiguation
  - name: Graphs
    description: Organize triples into graphs
  - name: Generation
    description: AI-powered triple generation from natural language
  - name: Indexes
    description: Organize entities into indexes
paths:
  /api/triples/generate:
    post:
      tags:
        - Generation
      summary: Generate triples
      description: >-
        Use OpenAI to extract knowledge triples from natural language. Supports
        web search for real-time information. Streams responses by default, use
        format=json for non-streaming.
      operationId: generateTriples
      parameters:
        - name: format
          in: query
          description: >-
            Response format. 'json' returns a standard JSON response (default,
            recommended for SDKs). 'stream' returns a Vercel AI SDK data stream
            for chat UIs.
          schema:
            type: string
            enum:
              - json
              - stream
            default: json
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateRequest'
            examples:
              simple:
                summary: Simple generation
                value:
                  query: Extract facts about Tesla's Q4 2025 earnings
                  index_id: 550e8400-e29b-41d4-a716-446655440000
                  triple_count: 10
              withWebSearch:
                summary: With web search enabled
                value:
                  query: What are the latest developments in quantum computing?
                  index_id: 550e8400-e29b-41d4-a716-446655440000
                  web_search: true
                  triple_count: 15
      responses:
        '200':
          description: Generated triples (streaming or JSON based on format parameter)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateTriplesResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '402':
          description: Insufficient credits
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InsufficientCreditsError'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    GenerateRequest:
      type: object
      required:
        - query
        - index_id
      description: Request to generate triples using AI (OpenAI)
      properties:
        query:
          type: string
          description: Natural language description of what to extract triples about
        graph_id:
          type: string
          format: uuid
          description: Graph to store generated triples in
        index_id:
          type: string
          format: uuid
          description: Index for entity disambiguation (required)
        web_search:
          type: boolean
          default: true
          description: Enable web search for real-time information
        triple_count:
          type: integer
          default: 10
          minimum: 1
          maximum: 50
          description: Target number of triples to generate (approximate)
        predicates:
          type: array
          items:
            type: string
          description: Restrict to specific predicate types
        subject_entity:
          type: string
          description: Constrain all generated triples to use this exact subject
        rules:
          type: string
          description: Custom rules or instructions for the AI generation
        news_search:
          type: boolean
          default: false
          description: Enable news-specific search for recent events
        create_graph:
          type: boolean
          default: true
          description: >-
            Auto-create a graph for generated triples when no graph_id is
            provided. When true (default) and no graph_id is given, a new graph
            is created and all generated triples are associated with it.
    GenerateTriplesResponse:
      type: object
      description: Response from generating triples with AI
      properties:
        success:
          type: boolean
        data:
          type: array
          items:
            $ref: '#/components/schemas/Triple'
        count:
          type: integer
        graph_id:
          type: string
          format: uuid
          description: Graph ID the triples were stored in (auto-created or provided)
        provider:
          type: string
          description: AI provider used (openai)
        credits_used:
          type: integer
          description: Credits deducted for generation
        balance_remaining:
          type: integer
          description: Remaining credit balance
        auto_topup_triggered:
          type: boolean
          description: Whether auto top-up was triggered after this generation
    InsufficientCreditsError:
      type: object
      description: Error returned when user has insufficient credits
      properties:
        success:
          type: boolean
          example: false
        error:
          type: string
        balance_cents:
          type: integer
        required_cents:
          type: integer
        buy_credits_url:
          type: string
    Triple:
      type: object
      description: A knowledge triple representing a fact as subject-predicate-object
      required:
        - subject
        - predicate
        - object
        - object_type
      properties:
        id:
          type: string
          format: uuid
          description: Unique identifier
        subject:
          type: string
          description: The subject entity (e.g., 'Elon Musk', 'Tesla')
        predicate:
          type: string
          description: The relationship type (e.g., 'founded', 'located_in', 'born_on')
        object:
          type: string
          description: The object value or entity (e.g., 'SpaceX', '2003', 'Austin, Texas')
        object_type:
          type: string
          enum:
            - literal
            - entity
          description: >-
            'literal' for values (dates, numbers, text), 'entity' for references
            to other entities
        confidence:
          type: number
          minimum: 0
          maximum: 1
          description: Confidence score (0-1) indicating reliability
        source:
          type: string
          format: uri
          description: Source URL or reference for this fact
        graph_id:
          type: string
          format: uuid
          description: Graph this triple belongs to
        index_id:
          type: string
          format: uuid
          description: Index for entity disambiguation
        subject_entity_id:
          type: string
          format: uuid
          description: Auto-resolved entity ID for subject
        object_entity_id:
          type: string
          format: uuid
          description: Auto-resolved entity ID for object (when object_type is 'entity')
        created_at:
          type: string
          format: date-time
    Error:
      type: object
      properties:
        success:
          type: boolean
          example: false
        error:
          type: string
        details:
          type: string
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InternalError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: API key for authentication

````