> ## 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.

# Libraries & SDKs

> Integrate Gloo AI into your applications using the official OpenAI libraries.

Gloo AI is **OpenAI-compatible**, so you can use the official OpenAI SDKs for Python and Node.js without learning a new syntax. Your API key is sent as a bearer token on every request.

Gloo adds platform-specific extensions to the OpenAI specification: [`auto_routing`](https://docs.gloo.com/getting-started/glossary#auto-routing), `model_family`, `tradition`, grounded completions, and response routing metadata. The [compatibility matrix](#compatibility-matrix) below maps the differences. Gloo supports both the **Responses API** and **Chat Completions**.

## Quick start

Both Responses endpoints work with `responses.create`: use the `/ai/v2/direct` base URL to go straight to the model ([Direct Responses](https://docs.gloo.com/api-guides/direct-responses.md)), or `/ai/v2/guarded` for Gloo's [guardrails](https://docs.gloo.com/ai-learning-center/gloo-ai-101/application-patterns.md#guardrails), moderation and `tradition` ([Responses](https://docs.gloo.com/api-guides/responses.md)). This example uses direct; for guarded, change only the base URL:

```python theme={null}
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("GLOO_API_KEY"),
    base_url="https://platform.ai.gloo.com/ai/v2/direct",
)
resp = client.responses.create(
    model="gloo-anthropic-claude-opus-5.5",
    input="Hello world!",
)
print(resp.output_text)
```

**Authentication:** Use your API key the same way you would with OpenAI — pass it as the `api_key` parameter in the SDK client. Get a key from the [API Keys page](https://docs.gloo.com/studio/manage-api-credentials.md) in Gloo AI Studio.

The Chat Completions examples below use the `/ai/v2/guarded` base URL. Each base URL serves both `responses.create` and `chat.completions.create`.

New to the SDK? Install it and set your key in [Install and configure the OpenAI SDK](#install-and-configure-the-openai-sdk) below.

## Install and configure the OpenAI SDK

> [tab] Python
>
> The Python library is the standard for AI engineering and data science.
>
> **1. Install the libraries**
>
> Install the OpenAI package with pip.
>
> ```bash theme={null}
> pip install openai python-dotenv
> ```
>
> **2. Set up environment variables**
>
> Create a `.env` file with your API key:
>
> ```bash theme={null}
> GLOO_API_KEY=your_api_key_here
> ```
>
> **3. Configure the client**
>
> Initialize the OpenAI client with your API key.
>
> ```python theme={null}
> import os
> from openai import OpenAI
> from dotenv import load_dotenv
>
> load_dotenv()
>
> client = OpenAI(
>     api_key=os.getenv("GLOO_API_KEY"),
>     base_url="https://platform.ai.gloo.com/ai/v2/guarded"
> )
>
> completion = client.chat.completions.create(
>     model="gloo-anthropic-claude-opus-5.5",
>     messages=[
>         {"role": "system", "content": "You are a helpful assistant."},
>         {"role": "user", "content": "Hello world!"}
>     ]
> )
>
> print(completion.choices[0].message.content)
> ```

> [tab] Node.js / TypeScript
>
> Perfect for full-stack developers and web applications.
>
> **1. Install the libraries**
>
> ```bash theme={null}
> npm install openai dotenv
> ```
>
> **2. Set up environment variables**
>
> Create a `.env` file with your API key:
>
> ```bash theme={null}
> GLOO_API_KEY=your_api_key_here
> ```
>
> **3. Configure the client**
>
> Initialize the OpenAI client with your API key.
>
> ```typescript theme={null}
> import OpenAI from "openai";
> import * as dotenv from "dotenv";
>
> dotenv.config();
>
> async function main() {
>   const client = new OpenAI({
>     apiKey: process.env.GLOO_API_KEY!,
>     baseURL: "https://platform.ai.gloo.com/ai/v2/guarded",
>   });
>
>   const completion = await client.chat.completions.create({
>     model: "gloo-anthropic-claude-opus-5.5",
>     messages: [{ role: "user", content: "Say this is a test" }],
>   });
>
>   console.log(completion.choices[0].message.content);
> }
>
> main();
> ```

> [!TIP]
>
> For production applications, store your API key in a secrets manager rather
> than in plaintext `.env` files. See [API Key
> Security](https://docs.gloo.com/best-practices/api-key-security.md) for secure key handling patterns.

## Other SDKs and endpoints

**Using the Anthropic SDK?** Keep it for Claude models: set the base URL to `https://platform.ai.gloo.com/ai/v2/direct/anthropic` and pass your Gloo API key as `auth_token`. See [Anthropic Messages](https://docs.gloo.com/api-guides/anthropic-messages.md).

The OpenAI SDK also supports `embeddings.create`. For [embedding](https://docs.gloo.com/ai-learning-center/gloo-ai-103/embeddings.md) examples and the `/ai/v2/direct` base URL, see the [Embeddings guide](https://docs.gloo.com/api-guides/embeddings.md). Embeddings requests use a dedicated endpoint and do not use the [model routing options](#passing-gloo-specific-parameters) described below.

## OpenAI Compatibility

Gloo AI's primary completions endpoint (`/ai/v2/guarded/chat/completions`) is shaped like OpenAI Chat Completions, so any client that accepts a custom `base_url` and `api_key` works with minimal changes. The table maps standard fields to Gloo AI equivalents.

### Compatibility Matrix

| Capability | OpenAI | Gloo AI |
| :- | :- | :- |
| **Authentication** | Static API key | Same — API key passed as `api_key` (bearer token) |
| **Base URL** | `https://api.openai.com/v1` | `https://platform.ai.gloo.com/ai/v2/guarded` |
| `messages` | Required | Required — same format |
| `model` | Required | Required by the SDK client; omit only when using `auto_routing` or `model_family` via direct HTTP |
| `stream` | Supported | Supported |
| `temperature` | Supported, 0 to 2 | Supported, 0 to 1: a value above 1 returns `422`. If you don't set it, the model's own default applies. Some models don't take one; see [Sampling parameters](https://docs.gloo.com/api-guides/direct-completions.md#sampling-parameters) |
| `max_tokens` | Supported | Supported, and `max_completion_tokens` too. On a [reasoning model](https://docs.gloo.com/ai-learning-center/gloo-ai-102/models-that-think.md) it holds the reasoning and 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) |
| `tools` / `tool_choice` | Supported | Supported |
| `auto_routing` | Not supported | **Gloo-specific** — opt-in: let Gloo select the model per request (default `false`) |
| `model_family` | Not supported | **Gloo-specific** — pick by provider (`openai`, `anthropic`, `google`, `open source`) |
| `tradition` | Not supported | **Gloo-specific** — theological perspective filter (`evangelical`, `catholic`, `mainline`) |
| Response routing metadata | Not included | **Gloo-specific** — `provider`, `model_family` and `routing_mechanism` on every response; `routing_tier` and `routing_confidence` only with `model_family` or `auto_routing` |
| Grounded ([RAG](https://docs.gloo.com/ai-learning-center/gloo-ai-101/data-and-memory.md#retrieval-augmented-generation-rag)) completions | Not supported | **Gloo-specific** — separate path `/ai/v2/grounded/chat/completions`; `base_url` and `model` differ |

> [!NOTE]
>
> Exactly one routing mechanism must be specified on every V2 request:
> `model`, `model_family`, or `auto_routing: true`. Unlike the OpenAI API,
> `model` is not always required—use `model_family` or opt in to
> `auto_routing: true` to let Gloo choose the model.

### Passing Gloo-Specific Parameters

How you pass Gloo-specific fields depends on whether you're specifying a model directly or using Gloo's routing.

**Using a model directly with optional filters (e.g. `tradition`)**

When `model` is present, you only need to forward the extra Gloo fields. In Python, use `extra_body`. In TypeScript, the OpenAI SDK doesn't have `extra_body`, so use the client's low-level `.post()` method instead.

```python Python theme={null}
response = client.chat.completions.create(
    model="gloo-anthropic-claude-haiku-4.5",
    messages=[{"role": "user", "content": "What does Ephesians 2:8-9 mean?"}],
    extra_body={"tradition": "evangelical"},
)
print(response.choices[0].message.content)
```

```typescript TypeScript theme={null}
// TypeScript SDK has no extra_body; use the client's .post() instead
const response = await (client as any).post('/chat/completions', {
  body: {
    model: 'gloo-anthropic-claude-haiku-4.5',
    messages: [{ role: 'user', content: 'What does Ephesians 2:8-9 mean?' }],
    tradition: 'evangelical',
  },
});
console.log(response.choices[0].message.content);
```

**Using Gloo routing (`model_family` or opt-in `auto_routing`)**

Both SDKs require `model` client-side. Gloo's routing modes don't send `model`, so call the API directly instead.

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

response = requests.post(
    "https://platform.ai.gloo.com/ai/v2/guarded/chat/completions",
    headers={
        "Authorization": f"Bearer {os.getenv('GLOO_API_KEY')}",
        "Content-Type": "application/json",
    },
    json={
        "messages": [{"role": "user", "content": "What does Ephesians 2:8-9 mean?"}],
        "model_family": "anthropic",
        "tradition": "evangelical",
    },
)
response.raise_for_status()
print(response.json()["choices"][0]["message"]["content"])
```

```typescript TypeScript theme={null}
const response = await (client as any).post('/chat/completions', {
  body: {
    messages: [{ role: 'user', content: 'What does Ephesians 2:8-9 mean?' }],
    model_family: 'anthropic',
    tradition: 'evangelical',
  },
});
console.log(response.choices[0].message.content);
```

> [!NOTE]
>
> The Grounded Completions endpoint uses a different base URL
> (`https://platform.ai.gloo.com/ai/v2/grounded`) and requires
> `rag_publisher` and other Gloo-specific fields. Use the same direct HTTP
> approach above. See the [Grounded Completions
> guide](https://docs.gloo.com/api-guides/grounded-completions.md) for full details.

## Supported Models

Use exact Gloo AI Model IDs with the SDK. Some common ones:

| Provider | Model ID |
| :- | :- |
| **Anthropic** | `gloo-anthropic-claude-opus-5.5` |
| **Anthropic** | `gloo-anthropic-claude-haiku-4.5` |
| **OpenAI** | `gloo-openai-gpt-6-luna` |
| **Google** | `gloo-google-gemini-3.5-flash-lite` |
| **Open Source** | `gloo-meta-llama-3.1-8b-instruct` |

> [!TIP]
>
> See the [Supported Models](https://docs.gloo.com/api-guides/supported-models.md) page for the full
> list of available Model IDs and their capabilities.

## Use Gloo AI in your editor or coding agent

### Gloo Code coding agent

For a fully autonomous [coding agent](https://docs.gloo.com/ai-learning-center/gloo-ai-104/coding-agents.md) rather than editor autocomplete, try [Gloo Code](https://docs.gloo.com/gloocode/overview.md). It runs as a standalone terminal agent that can plan, build, test, and commit code on its own, at up to 60–70% lower cost than equivalent direct-provider pricing.

> [!NOTE]
>
> **Gloo Code doesn't use the credentials on this page.** You sign in to it from
> the browser with your Gloo AI account, and it manages its own credential — no
> API key or [Client ID](https://docs.gloo.com/tutorials/authentication.md#legacy-client-credentials-and-oauth) to create. See the [Gloo Code installation
> guide](https://docs.gloo.com/gloocode/installation.md).

### Editors and agent frameworks

Because Gloo AI follows open standards, you can use it inside AI-native code editors (like **Cursor**, **Windsurf**, or **VS Code**) to "vibe code" with values-aligned models.

> [card] Cursor / VS Code
>
> 1. Go to **Settings > Models**
> 2. Add a Custom Provider
> 3. Set URL: `https://platform.ai.gloo.com/ai/v2/guarded`
> 4. Paste your API key

> [card] Agent Frameworks
>
> Compatible with **LangChain**, **CrewAI**, and **AutoGen** by setting the `openai_api_base` parameter and providing your API key.

> [!WARNING]
>
> Your API key doesn't time out like a short-lived access token, but it stops
> working if it passes an expiration date set for it or is revoked. When you
> rotate it, update the key everywhere it is configured, including your
> editor's custom provider settings. See the [API Keys
> page](https://docs.gloo.com/studio/manage-api-credentials.md) to manage keys.

**Connect our docs to your AI tools via [MCP](https://docs.gloo.com/ai-learning-center/gloo-ai-104/tools-and-mcp.md#what-mcp-is).** Get accurate API references, model IDs, and code examples directly in your editor or AI assistant. See the [MCP Integration](https://docs.gloo.com/api-guides/mcp-integration.md) guide to set up in one click.

## Next steps

> [card] [Direct Responses](https://docs.gloo.com/api-guides/direct-responses.md)
>
> The Responses format, straight to the model.

> [card] [Responses](https://docs.gloo.com/api-guides/responses.md)
>
> The Responses format with Gloo's guardrails, moderation and `tradition`.

> [card] [Developer Quickstart](https://docs.gloo.com/getting-started/quickstart-developers.md)
>
> Make your first API call.

> [card] [Authentication](https://docs.gloo.com/tutorials/authentication.md)
>
> Create and use API keys.


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