Contextual AI Generate API

Grounded generation with the Grounded Language Model (GLM).

Documentation

Specifications

Other Resources

OpenAPI Specification

contextual-ai-generate-api-openapi.yml Raw ↑
openapi: 3.0.1
info:
  title: Contextual AI Platform Agents Generate API
  description: REST API for the Contextual AI enterprise RAG platform. Provides agents (create / query grounded RAG agents), datastores and documents (ingest and manage the knowledge corpus), and standalone component APIs - Generate (grounded generation with the GLM), Rerank (instruction-following reranker), Parse (document parsing into AI-ready markdown), and LMUnit (natural-language unit-test evaluation). All endpoints authenticate with a Bearer API key.
  termsOfService: https://contextual.ai/terms-of-service/
  contact:
    name: Contextual AI Support
    url: https://docs.contextual.ai
    email: support@contextual.ai
  version: '1.0'
servers:
- url: https://api.contextual.ai/v1
  description: Contextual AI production API
security:
- bearerAuth: []
tags:
- name: Generate
  description: Grounded generation with the Grounded Language Model (GLM).
paths:
  /generate:
    post:
      operationId: generate
      tags:
      - Generate
      summary: Generate
      description: Generate a response grounded in supplied knowledge using the Grounded Language Model (GLM). The total request is limited to 32,000 tokens.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateRequest'
      responses:
        '200':
          description: Grounded generation result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateResponse'
        '422':
          $ref: '#/components/responses/ValidationError'
components:
  schemas:
    Message:
      type: object
      required:
      - role
      - content
      properties:
        role:
          type: string
          enum:
          - user
          - assistant
        content:
          type: string
    HTTPValidationError:
      type: object
      properties:
        detail:
          type: array
          items:
            $ref: '#/components/schemas/ValidationErrorDetail'
    GenerateRequest:
      type: object
      required:
      - model
      - messages
      - knowledge
      properties:
        model:
          type: string
          enum:
          - v1
          - v2
          description: Grounded Language Model (GLM) version.
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
          description: Conversation messages; the last must be from the user.
        knowledge:
          type: array
          items:
            type: string
          description: Knowledge sources to ground the response in.
        system_prompt:
          type: string
        avoid_commentary:
          type: boolean
          default: false
          description: Suppress non-grounded conversational text.
        temperature:
          type: number
          minimum: 0
          maximum: 1
          default: 0
        top_p:
          type: number
          default: 0.9
        max_new_tokens:
          type: integer
          minimum: 1
          maximum: 2048
          default: 1024
    GenerateResponse:
      type: object
      properties:
        response:
          type: string
          description: The model's answer to the user's final message.
    ValidationErrorDetail:
      type: object
      properties:
        loc:
          type: array
          items:
            oneOf:
            - type: string
            - type: integer
        msg:
          type: string
        type:
          type: string
  responses:
    ValidationError:
      description: Validation error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/HTTPValidationError'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Contextual AI API key supplied as a Bearer token.