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

# Grounded Completions

> Ground AI responses in your own content using RAG-powered completions with source attribution

The Gloo Grounded Completions API is Completions V2 with [Retrieval-Augmented Generation (RAG)](https://docs.gloo.com/ai-learning-center/gloo-ai-103/how-rag-actually-works.md) added. Before the model answers, Gloo looks up relevant passages in content you've uploaded and gives them to the model, so its answer draws on your own sources.

Use it when answers should come from specific content rather than only from the model's training. Set `rag_publisher` to your publisher name and the API handles retrieval, grounding, and attribution.

As on Completions V2, you get three model-selection options (direct model choice, [model family](https://docs.gloo.com/getting-started/glossary.md#model-family) selection, or opt-in auto-routing) plus [tradition-based](https://docs.gloo.com/api-guides/completions-v2.md#tradition-aware) personalization and input [guardrails](https://docs.gloo.com/ai-learning-center/gloo-ai-102/guardrails-and-values.md), with responses informed by sources retrieved from your content.

> [!NOTE]
>
> Grounded completions (RAG) and model-family and [auto-routing](https://docs.gloo.com/getting-started/glossary.md#auto-routing) selection are Completions V2 features. For general, OpenAI-compatible model access, use [Direct Responses](https://docs.gloo.com/api-guides/direct-responses.md) with nothing added, or the guarded [Responses API](https://docs.gloo.com/api-guides/responses.md) for Gloo's guardrails and `tradition`; RAG grounding in the Responses format is available via [Grounded Responses](https://docs.gloo.com/api-guides/grounded-responses.md).

## Prerequisites

You need:

* A Gloo AI Studio account
* Your API key from the [API Keys page](https://docs.gloo.com/studio/manage-api-credentials.md)
* **Authentication setup** - Complete the [Authentication Tutorial](https://docs.gloo.com/tutorials/authentication.md) first
* Content uploaded to your publisher: [upload your content](https://docs.gloo.com/api-guides/upload-content.md) before using grounded completions with your publisher
* For the Python example: the `requests` library (`pip install requests`). The TypeScript example uses the built-in `fetch` (Node 18+).

## Quick start

> [!NOTE]
>
> The grounded endpoint has its own base URL, `https://platform.ai.gloo.com/ai/v2/grounded`. Because OpenAI-compatible SDKs append `/chat/completions`, you can point an SDK client at that base URL when specifying a model. For requests that use `auto_routing` or `model_family` without a `model`, use a direct HTTP request instead because the SDK requires `model` client-side.

```bash cURL theme={null}
curl -X POST 'https://platform.ai.gloo.com/ai/v2/grounded/chat/completions' \
  -H 'accept: application/json' \
  -H "Authorization: Bearer $GLOO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "messages": [
    {
      "role": "user",
      "content": "What are practical ways to build stronger community in a local church?"
    }
  ],
  "model": "gloo-anthropic-claude-opus-5.5",
  "rag_publisher": "YourPublisherName",
  "sources_limit": 3,
  "tradition": "evangelical"
}'
```

```python Python theme={null}
import os
import requests

response = requests.post(
    "https://platform.ai.gloo.com/ai/v2/grounded/chat/completions",
    headers={
        "Authorization": f"Bearer {os.environ['GLOO_API_KEY']}",
        "Content-Type": "application/json",
    },
    json={
        "messages": [
            {
                "role": "user",
                "content": "What are practical ways to build stronger community in a local church?",
            }
        ],
        "model": "gloo-anthropic-claude-opus-5.5",
        "rag_publisher": "YourPublisherName",
        "sources_limit": 3,
        "tradition": "evangelical",
    },
)

data = response.json()
print(data["choices"][0]["message"]["content"])
```

```typescript TypeScript theme={null}
const response = await fetch(
  'https://platform.ai.gloo.com/ai/v2/grounded/chat/completions',
  {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.GLOO_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      messages: [
        {
          role: 'user',
          content:
            'What are practical ways to build stronger community in a local church?',
        },
      ],
      model: "gloo-anthropic-claude-opus-5.5",
      rag_publisher: 'YourPublisherName',
      sources_limit: 3,
      tradition: 'evangelical',
    }),
  },
);

const data = await response.json();
console.log(data.choices[0].message.content);
```

For a step-by-step build, follow the [Grounded Completions tutorial](https://docs.gloo.com/tutorials/completions-grounded.md): build a grounded chatbot with working code.

## Why Grounded Completions?

Grounded completions keep answers tied to your content:

| Benefit | What it means | Configuration |
| :- | :- | :- |
| **Reduced Hallucinations** | By grounding responses in content from your own dataset, rather than relying only on the model's training, you can reduce fabricated or incorrect information ([hallucinations](https://docs.gloo.com/ai-learning-center/gloo-ai-103/the-problem-rag-solves.md#when-ai-confidently-makes-things-up)). | — |
| **Content-Grounded Responses (RAG with Attribution)** | Responses draw on relevant sources retrieved from your uploaded content, with references included in the response. The `sources_returned` flag in the response tells you whether retrieved content was used to ground the answer. | `rag_publisher` set to your publisher name; `include_citations` for references |
| **Publisher-Scoped Knowledge** | You choose which knowledge base is retrieved from, so responses draw on your approved sources rather than generic web knowledge. | `rag_publisher` |
| **Routing Flexibility (Model Selection)** | Pick a specific model for consistent results (AI Select, recommended), select by provider family (AI Core Select), or opt in to auto-routing and let Gloo choose per request (AI Core). See [model selection](https://docs.gloo.com/getting-started/glossary.md#model-selection). | `model`, `model_family`, or `auto_routing` |
| **Tradition Personalization** | Customize responses for specific theological perspectives. | `tradition`: `catholic`, `evangelical`, `mainline` |
| **Input Guardrails** | Content validation before processing. | Automatic |

> [!NOTE]
>
> Grounding reduces fabrication; it does not verify that a given sentence appears in the retrieved sources. If your application serves quotations, titles, or attributions, check the answer against its sources before display. See [Building Trustworthy Grounded Applications](https://docs.gloo.com/best-practices/trustworthy-grounded-applications.md).

## Request Parameters

The request takes the Completions V2 fields plus the RAG fields below:

| Parameter | Type | Default | What it does |
| :- | :- | :- | :- |
| `model`, `model_family`, `auto_routing` | string, string, boolean | — | **Routing:** send exactly one of `model`, `model_family`, or `auto_routing: true`. Auto-routing is opt-in, and the selected model can change between calls, so avoid it when you need reproducible output or consistent tool calls. |
| `rag_publisher` | string | **GlooGrounded** | Your publisher name; see [Using Your Own Content](#using-your-own-content). |
| `sources_limit` | integer | 3 | How many sources are retrieved and considered (1-10); see [Source Limits](#source-limits). |
| `include_citations` | boolean | false | Include citation metadata for sources used by RAG; see [Include Citations](#include-citations). |
| `tradition` | string | — | Theological perspective; see [Tradition-Based Personalization](#tradition-based-personalization). |
| `temperature` | number | model default | If you don't set it, the model's own default applies. If you relied on the previous default, send `temperature: 0.7` to keep the same behaviour. |
| `max_tokens` | integer | — | Holds the reasoning as well as the answer. See [Set your output limit for reasoning models](https://docs.gloo.com/api-guides/reasoning.md#set-your-output-limit-for-reasoning-models). |
| `X-Cache-TTL` (header) | string | — | **Caching:** for Anthropic models, add the `X-Cache-TTL` header to enable explicit [prompt caching](https://docs.gloo.com/ai-learning-center/gloo-ai-104/cost-and-speed.md#prompt-caching). OpenAI and DeepSeek models use implicit caching automatically; for OpenAI you can add `prompt_cache_key` to improve hit rates. See [Prompt Caching](https://docs.gloo.com/api-guides/prompt-caching.md). |

For every parameter, see the [Grounded Completions API reference](https://docs.gloo.com/api-reference/completions/v2/grounded.md).

## RAG Configuration

### Using Your Own Content

Set the `rag_publisher` parameter to your publisher name to ground responses in your uploaded content:

```json theme={null}
{
  "messages": [
    {
      "role": "user",
      "content": "What resources do you have on family counseling?"
    }
  ],
  "model": "gloo-anthropic-claude-opus-5.5",
  "rag_publisher": "YourPublisherName"
}
```

The model only retrieves and references content from that publisher. Find your publisher name on the [Publishers page](https://docs.gloo.com/studio/manage-publishers.md) in Studio.

If you omit the `rag_publisher` parameter, the API falls back to **GlooGrounded**, a shared dataset assembled by Gloo. For best results, always specify your own publisher.

### Source Limits

Control how many sources are retrieved and considered with the `sources_limit` parameter (1-10, default is 3):

```json theme={null}
{
  "messages": [
    { "role": "user", "content": "What does Scripture say about forgiveness?" }
  ],
  "model": "gloo-anthropic-claude-opus-5.5",
  "sources_limit": 5
}
```

More sources give broader context but increase processing time. 3 sources work well for most queries; complex theological questions may benefit from more. Each source is one [chunk](https://docs.gloo.com/api-guides/chunking.md) of content, so the [chunk size](https://docs.gloo.com/api-guides/chunking.md#set-chunk-size-and-overlap) your content was uploaded with also sets how much text each source adds.

### Include Citations

Include citation metadata for sources used by RAG (defaults to false)

```json theme={null}
{
  "messages": [
    { "role": "user", "content": "What does Scripture say about forgiveness?" }
  ],
  "model": "gloo-anthropic-claude-opus-5.5",
  "include_citations": true
}
```

For [streaming](https://docs.gloo.com/ai-learning-center/gloo-ai-104/streaming-responses.md) responses, citations are prepended to the response in this format:

```json theme={null}
  "citations": [
    {
      "item_title": "",
      "item_url": "",
      "author": [
        ""
      ],
      "publisher": "",
      "publication_date": "",
      "snippets": [
        "",
        ""
      ]
    }
  ]
```

```json theme={null}
data: {"citations": [{"item_title": "", "item_url": "", "author": [""], "publisher": "", "publication_date": "", "snippets": ["", ""]}]}
```

## Tradition-Based Personalization

Customize responses to align with specific theological perspectives using the `tradition` parameter:

```json theme={null}
{
  "messages": [
    { "role": "user", "content": "Explain the concept of salvation" }
  ],
  "model": "gloo-anthropic-claude-opus-5.5",
  "tradition": "evangelical"
}
```

**Supported traditions:**

* `"evangelical"` - Evangelical Protestant perspective
* `"catholic"` - Roman Catholic perspective
* `"mainline"` - Mainline Protestant perspective
* `"not_faith_specific"` - Neutral, non-faith-specific perspective (uses Gloo's non-faith-specific prompt rather than a Christian tradition). **Requires an explicit `model`** and cannot be combined with `auto_routing` or `model_family`.

When specified, both RAG retrieval and generation adapt to the tradition, steering the language, concepts, and emphases of the answer.

## Response Format

### Non-Streaming Response

The response is a Completions V2 `chat.completion` object with grounding metadata added. An excerpt:

```json theme={null}
{
  "object": "chat.completion",
  "model": "gloo-anthropic-claude-opus-5.5",
  "choices": [
    {
      "index": 0,
      "finish_reason": "stop",
      "message": {
        "role": "assistant",
        "content": "Based on the retrieved sources, here are practical ways to build stronger community..."
      }
    }
  ],
  "routing_mechanism": "direct_model_selection",
  "tradition": "evangelical",
  "sources_returned": true,
  "citations": [
    {
      "item_title": "Daily Prayer",
      "item_url": "https://www.studio.ai.gloo.com",
      "author": ["John Doe"],
      "publisher": "The Publisher",
      "publication_date": "Apr 08 2017",
      "snippets": ["Daily prayer is an essential part of life as..."]
    }
  ]
}
```

`sources_returned` tells you whether retrieved content grounded the answer. `citations` appears only when you set `include_citations: true`. With a `reasoning_effort`, `message` can also carry `reasoning_content`; see [Reasoning](https://docs.gloo.com/api-guides/reasoning.md#chat-completions).

### Streaming Response

When `stream: true`, responses are sent as Server-Sent Events. Routing and RAG metadata is provided in HTTP headers:

| Header | Description |
| :- | :- |
| `X-Routing-Mechanism` | The routing mode used: `auto_routing`, `model_family`, `direct_model_selection` |
| `X-Selected-Model` | The Gloo model ID that handled the request |
| `X-Tradition` | Theological perspective used (if specified) |
| `X-Sources-Returned` | Whether RAG was used to retrieve and ground the response: `True` or `False` |
| `X-Routing-Tier` | Model tier selected (auto-routing only) |
| `X-Confidence` | Routing confidence score 0-1 (auto-routing only) |

When `include_citations: true` is set and sources are found, a `citations` event is the **first SSE chunk**, before any model content (see [Include Citations](#include-citations)). With a `reasoning_effort` other than `none`, `delta.reasoning_content` chunks arrive before the answer.

For every response field, see the [Grounded Completions API reference](https://docs.gloo.com/api-reference/completions/v2/grounded.md). For streaming implementation guidance, see [Completions V2](https://docs.gloo.com/api-guides/completions-v2.md).

## Next steps

> [card] [Step-by-step tutorial](https://docs.gloo.com/tutorials/completions-grounded.md)
>
> Build a grounded chatbot with working code.

> [card] [Building Trustworthy Grounded Applications](https://docs.gloo.com/best-practices/trustworthy-grounded-applications.md)
>
> Verifying answers against sources, prompt contracts, multi-turn handling, and evaluation.

> [card] [Grounded Responses](https://docs.gloo.com/api-guides/grounded-responses.md)
>
> The same RAG grounding in the Responses API format.

> [card] [API Reference](https://docs.gloo.com/api-reference/completions/v2/grounded.md)
>
> Every request and response field, with a live playground.

Also see: the [Completions V2 API](https://docs.gloo.com/api-guides/completions-v2.md) for core routing mechanisms and streaming details, the [Search API](https://docs.gloo.com/api-guides/search.md) for standalone RAG queries without generation, the [Tool Use Guide](https://docs.gloo.com/api-guides/tool-use.md) for using [function calling](https://docs.gloo.com/ai-learning-center/gloo-ai-104/tools-and-mcp.md) with grounded completions, [Supported Models](https://docs.gloo.com/api-guides/supported-models.md) for model capabilities and [context windows](https://docs.gloo.com/ai-learning-center/gloo-ai-101/prompting-and-generation.md#context-window), and how to [evaluate](https://docs.gloo.com/ai-learning-center/gloo-ai-101/metrics-and-evaluation.md) grounded answers.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.