---
title: "Generate"
method: POST
path: "/generate"
tags: ["/generate"]
---

# Generate

`POST /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.

## Request body

- GenerateRequestV1 — /generate input request object.
  - `model` string, required — The version of the Contextual's GLM to use. Currently, we have `v1` and `v2`.
  - `messages` MessageAndRoleGenerateAPI[], required — List of messages in the conversation so far. The last message must be from the user.
    - `content` string, required — Content of the message
    - `role` 'user' | 'assistant', required
  - `knowledge` string[], required — The knowledge sources the model can use when generating a response.
  - `system_prompt` string — Instructions that the model follows when generating responses. Note that we do not guarantee that the model follows these instructions exactly.
  - `avoid_commentary` boolean — 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.
  - `temperature` number — The sampling temperature, which affects the randomness in the response. Note that higher temperature values can reduce groundedness.
  - `top_p` number — 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.
  - `max_new_tokens` integer — The maximum number of tokens that the model can generate in the response.

## Response `200`

Successful Response

- GenerateResponseV1 — /generate result object.
  - `response` string, required — The model's response to the last user message.

## Other responses

- `422` — Validation Error

## Changes

- **2025-03-03** `f43814080090` — 2 breaking, 3 info
  - removed the enum value `knowledge` of the request property `messages/items/role`
  - removed the enum value `system` of the request property `messages/items/role`
  - added the new optional request property `max_new_tokens`
  - added the new optional request property `temperature`
  - …1 more
- **2025-02-26** `5298551c424b` — 1 breaking, 2 info
  - the `messages` request property's minItems was increased to `1`
  - added the new optional request property `avoid_commentary`
  - added the new `knowledge` enum value to the request property `messages/items/role`
- **2025-02-08** `d79ccb778953` — 1 info
  - endpoint added

[Change history](https://skmtc.dev/contextualai/apis/endpoints/changes/generate/post.md)

---

[API](https://skmtc.dev/contextualai/apis/endpoints.md) · [All operations](https://skmtc.dev/contextualai/apis/endpoints/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/contextualai/endpoints/revisions/ca7f807eec8b/schema)
