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

# Generate

> 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](https://contextual.ai/blog/introducing-grounded-language-model/) and [code examples](https://colab.research.google.com/github/ContextualAI/examples/blob/main/03-standalone-api/02-generate/generate.ipynb). Email [glm-feedback@contextual.ai](mailto:glm-feedback@contextual.ai) with any feedback or questions.



## OpenAPI

````yaml api-reference/openapi.json post /generate
openapi: 3.1.0
info:
  title: Endpoints
  version: '1.0'
servers:
  - url: https://api.contextual.ai/v1
security:
  - BearerAuth: []
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](https://contextual.ai/blog/introducing-grounded-language-model/)
        and [code
        examples](https://colab.research.google.com/github/ContextualAI/examples/blob/main/03-standalone-api/02-generate/generate.ipynb).
        Email [glm-feedback@contextual.ai](mailto: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:
    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.
    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
    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
    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
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key

````