Contextual AI Generate API

Grounded generation with the Grounded Language Model (GLM).

GitHub OpenAPI
Business capability
Model Inference AE-110.10

Operations 1

POST /generate Generate #

Documentation

Specifications

Other Resources

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/contextual-ai:contextual-ai-generate-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

contextual-ai-generate-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: Endpoints /generate API
  version: '1.0'
servers:
- url: https://api.contextual.ai/v1
security:
- BearerAuth: []
tags:
- name: /generate
paths:
  /generate:
    post:
      tags:
      - /generate
      summary: Generate
      description: 'Generate a response using Contextual''s Grounded Language Model (GLM), an LLM engineered specifically to prioritize faithfulness to in-context retrievals over parametric knowledge to reduce hallucinations in Retrieval-Augmented Generation and agentic use cases.


        The total request cannot exceed 32,000 tokens.


        See our blog post and code examples. Email glm-feedback@contextual.ai with any feedback or questions.'
      operationId: generate_generate_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateRequestV1'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateResponseV1'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    MessageAndRoleGenerateAPI:
      properties:
        content:
          type: string
          title: Content
          description: Content of the message
        role:
          $ref: '#/components/schemas/SenderTypeGenerateAPI'
          description: Role of the sender
      type: object
      required:
      - content
      - role
      title: MessageAndRoleGenerateAPI
      description: Message object for a message received in the /generate request
    GenerateRequestV1:
      properties:
        model:
          type: string
          title: Model
          description: The version of the Contextual's GLM to use. Currently, we have `v1` and `v2`.
        messages:
          items:
            $ref: '#/components/schemas/MessageAndRoleGenerateAPI'
          type: array
          minItems: 1
          title: Messages
          description: List of messages in the conversation so far. The last message must be from the user.
        knowledge:
          items:
            type: string
          type: array
          title: Knowledge
          description: The knowledge sources the model can use when generating a response.
        system_prompt:
          type: string
          title: System Prompt
          description: Instructions that the model follows when generating responses. Note that we do not guarantee that the model follows these instructions exactly.
        avoid_commentary:
          type: boolean
          title: Avoid Commentary
          description: Flag to indicate whether the model should avoid providing additional commentary in responses. Commentary is conversational in nature and does not contain verifiable claims; therefore, commentary is not strictly grounded in available context. However, commentary may provide useful context which improves the helpfulness of responses.
          default: false
        temperature:
          type: number
          maximum: 1
          minimum: 0
          title: Temperature
          description: The sampling temperature, which affects the randomness in the response. Note that higher temperature values can reduce groundedness.
          default: 0
        top_p:
          type: number
          maximum: 1
          exclusiveMinimum: 0
          title: Top_p
          description: A parameter for nucleus sampling, an alternative to temperature which also affects the randomness of the response. Note that higher top_p values can reduce groundedness.
          default: 0.9
        max_new_tokens:
          type: integer
          maximum: 2048
          minimum: 1
          title: Max New Tokens
          description: The maximum number of tokens that the model can generate in the response.
          default: 1024
      additionalProperties: false
      type: object
      required:
      - model
      - messages
      - knowledge
      title: GenerateRequestV1
      description: /generate input request object.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
            - type: string
            - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
      - loc
      - msg
      - type
      title: ValidationError
    SenderTypeGenerateAPI:
      type: string
      enum:
      - user
      - assistant
      title: SenderTypeGenerateAPI
    GenerateResponseV1:
      properties:
        response:
          type: string
          title: Response
          description: The model's response to the last user message.
      type: object
      required:
      - response
      title: GenerateResponseV1
      description: /generate result object.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
x-provenance:
  method: harvested
  publisher: Contextual AI
  source: https://docs.contextual.ai/api-reference/openapi.json
  note: split by refine-openapis from the provider's own published document, verified by fetch (openapi/_original/*.fetch.json);
    stamped by stamp-openapi-provenance.py (roadmap#793)