# AI Connections

These instructions apply to the current Admin Console.

## Description

An **AI Connection** (shown in the console as an **AI provider connection**) is a connection that includes an AI provider and the credentials needed to call that provider through Contextual’s AI Gateway. AI Connections are used by:

- [AI Routes](https://docs.contextual.io/connect/ai-routes.md)
- [AI Generate (Legacy)](https://docs.contextual.io/legacy/components-and-data/flows/node-reference/ai-gateway/ai-generate.md)

## Creating an AI Connection

1. In the left sidebar, under **Connect**, select **Connections**.
2. Select **New connection**, then select **AI provider connection**.
3. In the **New AI provider connection** dialog, enter a **Connection ID** and a **Name**, and choose an **AI provider**.
4. Complete the provider-specific fields described below.
5. Optional: expand **Advanced Configuration** to review or override the **Endpoint**. The endpoint is filled in from the fields above. To undo an override, select **Reset to Default**.
6. Select **Create**.

The new connection appears in the Connections list with an **AI connection** marker.

## Required Information

All AI Connections require:

| **Field**                      | **Required** | **Description**                                                                                                            |
|--------------------------------|--------------|----------------------------------------------------------------------------------------------------------------------------|
| **Connection ID** (`apiId`)    | Yes          | A unique identifier for this connection. Lower case letters, numbers, and dashes (`^[a-z0-9-]+$`). Can’t be changed later. |
| **Name** (`name`)              | Yes          | The display name for the connection.                                                                                       |
| **AI provider** (`aiProvider`) | Yes          | One of: OpenAI, Anthropic, Azure OpenAI, Google AI, Vertex AI, Vertex Anthropic, or OpenAI Compatible.                     |

### OpenAI

- **API key** (`bearerToken`): required.
- **Endpoint** (under **Advanced Configuration**): default `https://api.openai.com/v1`.
- Underlying connection type: `bearer`.

**OpenAI** connections use the OpenAI Responses API. For a provider that isn’t offered directly but implements the OpenAI Chat Completions API, use an [**OpenAI Compatible**](https://docs.contextual.io/connect/connections/types-of-connections/ai-connections.md#openai-compatible) connection.

### OpenAI Compatible

Use an OpenAI Compatible connection for a provider that AI Gateway doesn’t offer directly and that accepts OpenAI-style Chat Completions requests.

- **API key** (`bearerToken`): required. Sent using bearer authentication.
- **Base URL** (`endpoint`): required. Shown in the main form, not under **Advanced Configuration**. Enter the provider’s complete API base URL, including `/v1` or the provider’s equivalent path prefix.
- Underlying connection type: `bearer`.

AI Gateway keeps the URL path prefix and appends `/chat/completions`, so leave that suffix out of **Base URL**. It doesn’t add `/v1` for you.

For example, with this **Base URL**:

```text
https://inference.example.com/team/deployment/v1
```

AI Gateway sends generation requests to:

```text
https://inference.example.com/team/deployment/v1/chat/completions
```

This is an illustrative URL; use the base URL supplied by your provider.

After saving the connection, add it to an [AI Route](https://docs.contextual.io/connect/ai-routes.md#model-providers). In the route’s **Details** section, under **Model Providers**, select the connection in **AI Provider Connection** and enter the provider’s exact model ID in **Model**. Supported inputs and features depend on the provider and model.

### Anthropic

- **API key**: required. Stored in headers as `x-api-key`.
- **Endpoint** (under **Advanced Configuration**): default `https://api.anthropic.com/v1`.
- Underlying connection type: `public`.

### Azure OpenAI

- **Resource name** (`aiProviderData.resourceName`): required. Your Azure OpenAI resource name, which is the endpoint subdomain.
- **API key**: required. Stored in headers as `api-key`.
- **Endpoint** (under **Advanced Configuration**): generated from the resource name as `https://{resourceName}.openai.azure.com/openai`. Can be overridden.
- Underlying connection type: `public`.

### Google AI

Google AI connections call the Gemini API.

- **API key**: required. Stored in headers as `x-goog-api-key`.
- **Endpoint** (under **Advanced Configuration**): default `https://generativelanguage.googleapis.com/v1beta`.
- Underlying connection type: `public`.

### Vertex AI

- **Project ID** (`aiProviderData.projectId`): required.
- **Location** (`aiProviderData.location`): required. For example, `us-central1` or `global`.
- **Service account key** (`key`): required. Paste the full service-account JSON. Stored as a secret.
- **Endpoint** (under **Advanced Configuration**): generated from the project ID and location. Can be overridden.
- Underlying connection type: `google-service-account` (scope `https://www.googleapis.com/auth/cloud-platform`).

### Vertex Anthropic

Same fields as Vertex AI, but routes to Anthropic models through Vertex AI’s Anthropic publisher endpoint. Anthropic models must be enabled for each Vertex AI account, so make sure you are opted in to the Anthropic model you want to use through Vertex.

For **Vertex AI** and **Vertex Anthropic**, choose a **Location** supported by your model. See [Google’s endpoint and location documentation](https://docs.cloud.google.com/gemini-enterprise-agent-platform/resources/locations) and [Anthropic’s Claude on Google Cloud guide](https://platform.claude.com/docs/en/build-with-claude/claude-models-on-google-cloud/google-managed) for provider requirements and model availability.

If **Location** is `global` or a multi-region location (`us` or `eu`), expand **Advanced Configuration** and change the generated **Endpoint** hostname to the corresponding hostname in the vendor documentation linked above. Keep the rest of the URL unchanged.

## Headers Note

When calling a provider directly through a Contextual HTTP node, configure additional request headers in that node’s **Headers** settings.

AI Routes and AI Gateway use the connection’s provider credentials, including API keys stored in headers. They do not forward additional custom headers from the connection.

## Editing an AI Connection

After creation, the connection’s detail page and **Edit** dialog show the fields of its underlying connection type. For example, an OpenAI connection shows **Endpoint** and **Bearer Token**.

## Usage

- AI Routes only let you select connections that have an AI provider configured (AI Connections).
- To call the provider manually from HTTP nodes, use the connection’s **Endpoint** as the base URL.
- AI Connections are standard Contextual connections, so you can use them anywhere a connection is accepted. For example, in Legacy Flows, select an AI Connection in an [HTTP node](https://docs.contextual.io/legacy/components-and-data/flows/node-reference/network/http-request.md) to call the provider API directly, without an AI Route or the AI Generate node.
