# Phase 8: External Models (Optional)

> The ExternalModel CRD lets you expose third-party LLM APIs (OpenAI, AWS Bedrock, Google Gemini, Anthropic, Azure OpenAI, etc.) through the MaaS gateway.

---

LLMS index: [llms.txt](/CAI-Field-Manual-MaaS/llms.txt)

---

> [!NOTE]
> This phase requires a completed MaaS installation (through [Phase 4](/CAI-Field-Manual-MaaS/maas/installation-guide/rhoai-config/)) and at least one local model deployed ([Phase 5](/CAI-Field-Manual-MaaS/maas/model-deployment/maas-models/)) to validate the gateway is functional.

> [!WARNING]
> This phase is NOT compatible with disconnected/air-gapped environments. External models require internet access to reach third-party APIs (OpenAI, Bedrock, Gemini, Anthropic, Azure OpenAI). If you are running in disconnected mode, skip this phase entirely.

The `ExternalModel` CRD lets you expose third-party LLM APIs (OpenAI, AWS Bedrock, Google Gemini, Anthropic, Azure OpenAI, etc.) through the MaaS gateway. External models get the same API key management, authentication, rate limiting, and usage tracking as locally-served models - your consumers use a single gateway endpoint regardless of where the model runs.

> [!TIP]
> All file paths and `oc apply` commands in this guide are relative to the [CAI-Field-Manual-MaaS](https://github.com/rh-aiservices-bu/CAI-Field-Manual-MaaS) repository root. Make sure you have cloned it and are working from its root directory (see [Getting Started](/CAI-Field-Manual-MaaS/maas/#getting-started)).

> [!IMPORTANT]
> This guide is not a replacement for the official Red Hat OpenShift AI Models as a Service documentation ([3.5](https://docs.redhat.com/en/documentation/red_hat_openshift_ai_self-managed/3.5/html/govern_llm_access_with_models-as-a-service/index) | [3.4](https://docs.redhat.com/en/documentation/red_hat_openshift_ai_self-managed/3.4/html/govern_llm_access_with_models-as-a-service/index)). It is a companion resource with opinionated Kustomize manifests and automation scripts to accelerate deployment.

## How It Works

**RHAIE Version: 3.5, 3.6**


An external model deployment requires six resources:

1. **Secret** - stores the provider API key. Must have the label `inference.llm-d.ai/ipp-managed=true` so the payload-processing ext-proc can inject the credential into upstream requests.

2. **ExternalProvider** - defines the provider endpoint and authentication configuration (API type, secret reference).

3. **ExternalModel** - references the provider and maps the model with routing config (`apiFormat`, `path`, `targetModel`). The BBR (Backend Binding Resolver) handles path rewriting and authentication header injection.

4. **MaaSModelRef** - registers the external model in the MaaS catalog so it appears in the API and can be governed.

5. **MaaSAuthPolicy** - grants access to specific users or groups.

6. **MaaSSubscription** - sets rate limits (tokens per hour) and priority.


**RHAIE Version: 3.4**


An external model deployment requires five resources:

1. **Secret** - stores the provider API key. Must have the label `inference.networking.k8s.io/bbr-managed=true` so the BBR ext-proc can inject the credential into upstream requests.

2. **ExternalModel** - defines the provider, target model, endpoint, and credential reference. The BBR (Backend Binding Resolver) handles path rewriting and authentication header injection.

3. **MaaSModelRef** - registers the external model in the MaaS catalog so it appears in the API and can be governed.

4. **MaaSAuthPolicy** - grants access to specific users or groups.

5. **MaaSSubscription** - sets rate limits (tokens per hour) and priority.


## Step 1: Create the Namespace and Secret

The external models live in their own namespace, separate from the MaaS platform and local models:

```sh
oc apply -f manifests/08-external-models/openai/namespace.yaml
```

> [!NOTE]
> The namespace manifest includes the `maas.opendatahub.io/gateway-access=true` label, which is required for the Gateway to accept HTTPRoutes from this namespace. If you create the namespace manually instead of using the manifest, remember to apply this label: `oc label namespace external-models maas.opendatahub.io/gateway-access=true --overwrite`

Create the provider credential Secret. This is done imperatively (never stored in manifests):

**RHAIE Version: 3.5, 3.6**


```sh
oc create secret generic openai-api-key \
    --from-literal=api-key="$OPENAI_API_KEY" \
    -n external-models \
    --dry-run=client -o yaml | oc apply -f -

oc label secret openai-api-key -n external-models \
    inference.llm-d.ai/ipp-managed=true --overwrite
```

> [!IMPORTANT]
> The `inference.llm-d.ai/ipp-managed=true` label is required. Without it, the payload-processing ext-proc will not inject the API key and inference will fail with a 500 "credentials not found" error.


**RHAIE Version: 3.4**


```sh
oc create secret generic openai-api-key \
    --from-literal=api-key="$OPENAI_API_KEY" \
    -n external-models \
    --dry-run=client -o yaml | oc apply -f -

oc label secret openai-api-key -n external-models \
    inference.networking.k8s.io/bbr-managed=true --overwrite
```

> [!IMPORTANT]
> The `inference.networking.k8s.io/bbr-managed=true` label is required. Without it, the BBR ext-proc will not inject the API key and the provider will reject calls with 401.


## Step 2: Apply the External Model Resources

Apply the model definition resources. The CRD structure changed between RHOAI versions:

**RHAIE Version: 3.5, 3.6**


```sh
oc apply -k manifests/08-external-models/openai/model/
```

This creates two resources - the `ExternalProvider` and `ExternalModel`:

```yaml
apiVersion: inference.opendatahub.io/v1alpha1
kind: ExternalProvider
metadata:
  name: openai
  namespace: external-models
spec:
  provider: openai
  endpoint: api.openai.com
  auth:
    type: apikey
    secretRef:
      name: openai-api-key
---
apiVersion: inference.opendatahub.io/v1alpha1
kind: ExternalModel
metadata:
  name: gpt-4o-mini
  namespace: external-models
spec:
  modelName: gpt-4o-mini
  externalProviderRefs:
    - ref:
        name: openai
      targetModel: gpt-4o-mini
      apiFormat: openai-chat
      path: /v1/chat/completions
```


**RHAIE Version: 3.4**


```sh
oc apply -f manifests/08-external-models/openai/model/external-model-34.yaml
```

This creates the `ExternalModel` resource:

```yaml
apiVersion: maas.opendatahub.io/v1alpha1
kind: ExternalModel
metadata:
  name: gpt-4o-mini
  namespace: external-models
spec:
  provider: openai
  targetModel: gpt-4o-mini
  endpoint: api.openai.com
  credentialRef:
    name: openai-api-key
```


## Step 3: Apply MaaS Governance

```sh
oc apply -k manifests/08-external-models/openai/maas/
```

This creates three resources:

- `MaaSModelRef` - registers `gpt-4o-mini` in the MaaS catalog
- `MaaSAuthPolicy` - grants all authenticated users access
- `MaaSSubscription` - sets a free tier with 10,000 tokens/hour rate limit

## Verification

Check the MaaSModelRef reaches `Ready`:

```sh
oc get maasmodelref gpt-4o-mini -n external-models
# Expected: PHASE = Ready
```

Check the model appears in the MaaS API:

```sh
MAAS_GW="https://maas.$(oc get ingresses.config/cluster -o jsonpath='{.spec.domain}')"
curl -sk "${MAAS_GW}/maas-api/v1/models" \
    -H "Authorization: Bearer $(oc whoami -t)" | python3 -m json.tool
```

Create an API key and test inference:

```sh
# Create an API key bound to the openai-free subscription
API_KEY=$(curl -sk -X POST "${MAAS_GW}/maas-api/v1/api-keys" \
    -H "Authorization: Bearer $(oc whoami -t)" \
    -H "Content-Type: application/json" \
    -d '{"name": "openai-test", "subscription": "openai-free", "expiresIn": "1h"}' \
    | python3 -c "import sys,json; print(json.load(sys.stdin)['key'])")

# Test inference (body-based routing)
curl -sk "${MAAS_GW}/v1/chat/completions" \
    -H "Authorization: Bearer ${API_KEY}" \
    -H "Content-Type: application/json" \
    -d '{"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Say hello in 3 words."}], "max_tokens": 20}'
```

A successful response contains a `choices` array with the model's reply.

> [!NOTE]
> External models use the plain model name (e.g., `gpt-4o-mini`) as the `model` field, unlike local models which require the canonical `publishers/{namespace}/models/{model-name}` format. You can always check the correct model ID with the `/v1/models` endpoint.

## Automated Setup

The setup script handles all of the above in a single command:

```sh
./scripts/setup-maas.sh --from-phase 8 \
    --with-external-models \
    --external-model-provider openai \
    --external-model-api-key "$OPENAI_API_KEY"
```

The `--external-model-provider` flag selects which provider manifests to deploy (`openai`, `gemini`, `bedrock`, `anthropic`, or `azure-openai`; default: `openai`).

## Dashboard UI (Technology Preview) {#dashboard-ui}

> [!IMPORTANT]
> The **External models** tab in the RHOAI Dashboard is a **Technology Preview** feature in RHOAI 3.5. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. The CLI workflow documented above (Steps 1-3) is the fully supported (GA) method for managing external models.

The Dashboard provides an admin-only view of external models deployed through the CLI. This tab is enabled by the `externalModels: true` flag in the OdhDashboardConfig (see [Phase 4: Check OdhDashboardConfig flags](/CAI-Field-Manual-MaaS/maas/installation-guide/rhoai-config/#check-odhdashboardconfig-flags)).

Navigate to **AI hub > Models > Deployments** and select the **External models** tab:

![External models tab under Deployments showing gpt-4o-mini with provider details](images/external-models-deployments-tab.png)

The tab lists each external model with its provider badge and status. Expanding a model row shows the full provider configuration: external provider name, provider URL, path, authentication type, credential secret, API format, target model ID, and weight.

> [!NOTE]
> The Dashboard provides a read-only view of the same Kubernetes CRDs created by the CLI workflow (`ExternalProvider`, `ExternalModel`). To create or modify external models, use the CLI steps documented above. Models created via `oc apply` appear in the Dashboard automatically.

## Other Providers

### Google Gemini {#google-gemini}

Manifests for Google Gemini (`gemini-2.5-flash`) are included under `manifests/08-external-models/gemini/`. To deploy Gemini instead of OpenAI, use `--external-model-provider gemini`.

> [!NOTE]
> On RHOAI 3.4, there is a known incompatibility: the BBR `openai` provider hardcodes the upstream path to `/v1/chat/completions`, but Gemini requires `/v1beta/openai/chat/completions`, causing inference to return HTTP 404. This was tracked in [RHOAIENG-68592](https://redhat.atlassian.net/browse/RHOAIENG-68592). On RHOAI 3.5+, the `ExternalModel` CRD includes a `path` field in `externalProviderRefs` that overrides the upstream path, so Gemini works end-to-end.

To deploy with Gemini:

```sh
./scripts/setup-maas.sh --from-phase 8 \
    --with-external-models \
    --external-model-provider gemini \
    --external-model-api-key "$GEMINI_API_KEY"
```

### Anthropic {#anthropic}

Manifests for Anthropic (`claude-haiku-4-5`) are included under `manifests/08-external-models/anthropic/`. The BBR `anthropic` provider translates OpenAI-format requests to the Anthropic Messages API and injects the API key via the `x-api-key` header - consumers still send standard OpenAI-format requests to the gateway.

> [!NOTE]
> On RHOAI 3.4, the `anthropic` BBR provider must handle path rewriting internally (there is no `path` field on the ExternalModel CRD). This has not been validated on 3.4 - if inference returns errors, upgrade to RHOAI 3.5+ where the `path` field explicitly sets `/v1/messages`.

> [!WARNING]
> Clients **must** use the OpenAI-compatible endpoint (`/v1/chat/completions`) when sending requests through the MaaS gateway. The Anthropic-native Messages API endpoint (`/v1/messages`) is not supported for token counting or rate limiting ([RHOAIENG-93984](https://redhat.atlassian.net/browse/RHOAIENG-93984)). Tools like Claude Code that default to Anthropic's native API format need to be configured for OpenAI-compatible mode. The ExternalModel flow documented below routes through `/v1/chat/completions` and handles this correctly - the BBR translates to Anthropic format upstream.

#### Prerequisites

Get an API key from the [Anthropic Console](https://console.anthropic.com/settings/keys) (Account Settings > API keys).

> [!TIP]
> Verify the key works before deploying: `curl -s "https://api.anthropic.com/v1/messages" -H "x-api-key: $ANTHROPIC_API_KEY" -H "anthropic-version: 2023-06-01" -H "Content-Type: application/json" -d '{"model":"claude-haiku-4-5-20251001","max_tokens":5,"messages":[{"role":"user","content":"Hi"}]}' | python3 -m json.tool`

#### Manual Deployment

Create the namespace if it does not already exist (shared with other external model providers):

```sh
oc apply -f manifests/08-external-models/anthropic/namespace.yaml
```

Create the credential Secret (never stored in manifests):

**RHAIE Version: 3.5, 3.6**


```sh
oc create secret generic anthropic-api-key \
    --from-literal=api-key="$ANTHROPIC_API_KEY" \
    -n external-models \
    --dry-run=client -o yaml | oc apply -f -

oc label secret anthropic-api-key -n external-models \
    inference.llm-d.ai/ipp-managed=true --overwrite
```


**RHAIE Version: 3.4**


```sh
oc create secret generic anthropic-api-key \
    --from-literal=api-key="$ANTHROPIC_API_KEY" \
    -n external-models \
    --dry-run=client -o yaml | oc apply -f -

oc label secret anthropic-api-key -n external-models \
    inference.networking.k8s.io/bbr-managed=true --overwrite
```


Apply the external model and MaaS governance resources:

**RHAIE Version: 3.5, 3.6**


```sh
oc apply -k manifests/08-external-models/anthropic/model/
oc apply -k manifests/08-external-models/anthropic/maas/
```

The ExternalProvider and ExternalModel CRs:

```yaml
apiVersion: inference.opendatahub.io/v1alpha1
kind: ExternalProvider
metadata:
  name: anthropic
  namespace: external-models
spec:
  provider: anthropic
  endpoint: api.anthropic.com
  auth:
    type: apikey
    secretRef:
      name: anthropic-api-key
---
apiVersion: inference.opendatahub.io/v1alpha1
kind: ExternalModel
metadata:
  name: claude-haiku-4-5
  namespace: external-models
spec:
  modelName: claude-haiku-4-5
  externalProviderRefs:
    - ref:
        name: anthropic
      targetModel: claude-haiku-4-5-20251001
      apiFormat: openai-chat
      path: /v1/messages
```


**RHAIE Version: 3.4**


```sh
oc apply -f manifests/08-external-models/anthropic/model/external-model-34.yaml
oc apply -k manifests/08-external-models/anthropic/maas/
```

The ExternalModel CR:

```yaml
apiVersion: maas.opendatahub.io/v1alpha1
kind: ExternalModel
metadata:
  name: claude-haiku-4-5
  namespace: external-models
spec:
  provider: anthropic
  targetModel: claude-haiku-4-5-20251001
  endpoint: api.anthropic.com
  credentialRef:
    name: anthropic-api-key
```


Verify the model reaches Ready:

```sh
oc get maasmodelref claude-haiku-4-5 -n external-models
# Expected: PHASE = Ready
```

Test inference:

```sh
MAAS_GW="https://maas.$(oc get ingresses.config/cluster -o jsonpath='{.spec.domain}')"

API_KEY=$(curl -sk -X POST "${MAAS_GW}/maas-api/v1/api-keys" \
    -H "Authorization: Bearer $(oc whoami -t)" \
    -H "Content-Type: application/json" \
    -d '{"name": "anthropic-test", "subscription": "anthropic-free", "expiresIn": "1h"}' \
    | python3 -c "import sys,json; print(json.load(sys.stdin)['key'])")

curl -sk "${MAAS_GW}/v1/chat/completions" \
    -H "Authorization: Bearer ${API_KEY}" \
    -H "Content-Type: application/json" \
    -d '{"model": "claude-haiku-4-5", "messages": [{"role": "user", "content": "Say hello in 3 words."}], "max_tokens": 20}'
```

#### Automated Deployment

```sh
./scripts/setup-maas.sh --from-phase 8 \
    --with-external-models \
    --external-model-provider anthropic \
    --external-model-api-key "$ANTHROPIC_API_KEY"
```

### AWS Bedrock {#aws-bedrock}

Manifests for AWS Bedrock (`openai.gpt-oss-20b` via the Mantle endpoint) are included under `manifests/08-external-models/bedrock/`. Bedrock uses the `bedrock-openai` provider, which routes through the OpenAI-compatible Mantle API - no request body translation is needed.

> [!WARNING]
> Use `bedrock-mantle.<region>.api.aws`, **not** `bedrock-runtime.<region>.amazonaws.com`. The BBR translator uses `/v1/chat/completions`, which is only available on the Mantle endpoint. Using `bedrock-runtime` will result in 404 errors.

#### Prerequisites

Bedrock requires a **Bedrock API Key** (ABSK key), not standard AWS access keys. Create one via IAM service-specific credentials:

```sh
# Create an IAM user for Bedrock API access
aws iam create-user --user-name bedrock-api-user

# Attach Bedrock access policy
aws iam attach-user-policy \
    --user-name bedrock-api-user \
    --policy-arn arn:aws:iam::aws:policy/AmazonBedrockLimitedAccess

# Generate a long-term ABSK key (up to 90 days)
aws iam create-service-specific-credential \
    --user-name bedrock-api-user \
    --service-name bedrock.amazonaws.com \
    --credential-age-days 90
```

The output contains a `ServiceSpecificCredential.ServicePassword` field starting with `ABSK` - this is the API key to use.

> [!TIP]
> Verify the ABSK key works before deploying: `curl -s "https://bedrock-mantle.us-east-2.api.aws/v1/models" -H "Authorization: Bearer $BEDROCK_API_KEY" | python3 -m json.tool`

#### Manual Deployment

Create the namespace if it does not already exist (shared with other external model providers):

```sh
oc apply -f manifests/08-external-models/bedrock/namespace.yaml
```

Create the credential Secret (never stored in manifests):

**RHAIE Version: 3.5, 3.6**


```sh
oc create secret generic bedrock-api-key \
    --from-literal=api-key="$BEDROCK_API_KEY" \
    -n external-models \
    --dry-run=client -o yaml | oc apply -f -

oc label secret bedrock-api-key -n external-models \
    inference.llm-d.ai/ipp-managed=true --overwrite
```


**RHAIE Version: 3.4**


```sh
oc create secret generic bedrock-api-key \
    --from-literal=api-key="$BEDROCK_API_KEY" \
    -n external-models \
    --dry-run=client -o yaml | oc apply -f -

oc label secret bedrock-api-key -n external-models \
    inference.networking.k8s.io/bbr-managed=true --overwrite
```


Apply the external model and MaaS governance resources:

**RHAIE Version: 3.5, 3.6**


```sh
oc apply -k manifests/08-external-models/bedrock/model/
oc apply -k manifests/08-external-models/bedrock/maas/
```

The ExternalProvider and ExternalModel CRs:

```yaml
apiVersion: inference.opendatahub.io/v1alpha1
kind: ExternalProvider
metadata:
  name: bedrock
  namespace: external-models
spec:
  provider: bedrock-openai
  endpoint: bedrock-mantle.us-east-2.api.aws
  auth:
    type: apikey
    secretRef:
      name: bedrock-api-key
---
apiVersion: inference.opendatahub.io/v1alpha1
kind: ExternalModel
metadata:
  name: aws-gpt-oss-20b
  namespace: external-models
spec:
  modelName: openai.gpt-oss-20b
  externalProviderRefs:
    - ref:
        name: bedrock
      targetModel: openai.gpt-oss-20b
      apiFormat: openai-chat
      path: /v1/chat/completions
```


**RHAIE Version: 3.4**


```sh
oc apply -f manifests/08-external-models/bedrock/model/external-model-34.yaml
oc apply -k manifests/08-external-models/bedrock/maas/
```

The ExternalModel CR:

```yaml
apiVersion: maas.opendatahub.io/v1alpha1
kind: ExternalModel
metadata:
  name: aws-gpt-oss-20b
  namespace: external-models
spec:
  provider: bedrock-openai
  targetModel: openai.gpt-oss-20b
  endpoint: bedrock-mantle.us-east-2.api.aws
  credentialRef:
    name: bedrock-api-key
```


> [!NOTE]
> The `endpoint` must match your AWS region. Replace `us-east-2` with your region if different.

Verify the model reaches Ready:

```sh
oc get maasmodelref aws-gpt-oss-20b -n external-models
# Expected: PHASE = Ready
```

Test inference:

```sh
MAAS_GW="https://maas.$(oc get ingresses.config/cluster -o jsonpath='{.spec.domain}')"

API_KEY=$(curl -sk -X POST "${MAAS_GW}/maas-api/v1/api-keys" \
    -H "Authorization: Bearer $(oc whoami -t)" \
    -H "Content-Type: application/json" \
    -d '{"name": "bedrock-test", "subscription": "bedrock-free", "expiresIn": "1h"}' \
    | python3 -c "import sys,json; print(json.load(sys.stdin)['key'])")

curl -sk "${MAAS_GW}/v1/chat/completions" \
    -H "Authorization: Bearer ${API_KEY}" \
    -H "Content-Type: application/json" \
    -d '{"model": "aws-gpt-oss-20b", "messages": [{"role": "user", "content": "Say hello in 3 words."}], "max_tokens": 20}'
```

#### Automated Deployment

```sh
./scripts/setup-maas.sh --from-phase 8 \
    --with-external-models \
    --external-model-provider bedrock \
    --external-model-api-key "$BEDROCK_API_KEY"
```

### Azure OpenAI {#azure-openai}

Manifests for Azure OpenAI (`gpt-4.1-mini` deployment) are included under `manifests/08-external-models/azure-openai/`. The BBR `azure-openai` provider routes requests through Azure's OpenAI Service - consumers send standard OpenAI-format requests to the gateway and the BBR handles Azure-specific path construction and API key injection via the `api-key` header.

> [!NOTE]
> On RHOAI 3.4, the `azure-openai` BBR provider must handle Azure path rewriting internally (there is no `path` field on the ExternalModel CRD). This has not been validated on 3.4 - if inference returns errors, upgrade to RHOAI 3.5+ where the `path` field explicitly sets the Azure deployment path.

> [!WARNING]
> The `endpoint` in the ExternalProvider manifest must match your Azure OpenAI resource. Replace `<your-resource>.openai.azure.com` with your actual resource hostname (e.g., `myresource.openai.azure.com`). Similarly, the `path` in the ExternalModel must match your deployment name and API version.

#### Prerequisites

You need an Azure OpenAI resource with a deployed model. Create one via the [Azure Portal](https://portal.azure.com/#create/Microsoft.CognitiveServicesOpenAI) or the Azure CLI:

```sh
# Create an Azure OpenAI resource
az cognitiveservices account create \
    --name <your-resource-name> \
    --resource-group <your-resource-group> \
    --kind OpenAI \
    --sku S0 \
    --location eastus2

# Deploy gpt-4.1-mini
az cognitiveservices account deployment create \
    --name <your-resource-name> \
    --resource-group <your-resource-group> \
    --deployment-name gpt-4-1-mini \
    --model-name gpt-4.1-mini \
    --model-version "2025-04-14" \
    --model-format OpenAI \
    --sku-capacity 10 \
    --sku-name GlobalStandard
```

Get the API key from the Azure Portal (Resource > Keys and Endpoint) or via CLI:

```sh
export AZURE_OPENAI_API_KEY=$(az cognitiveservices account keys list \
    --name <your-resource-name> \
    --resource-group <your-resource-group> \
    --query key1 -o tsv)
```

> [!TIP]
> Verify the key works before deploying: `curl -s "https://<your-resource>.openai.azure.com/openai/deployments/gpt-4-1-mini/chat/completions?api-version=2025-04-01-preview" -H "api-key: $AZURE_OPENAI_API_KEY" -H "Content-Type: application/json" -d '{"messages":[{"role":"user","content":"Hi"}],"max_tokens":5}' | python3 -m json.tool`

#### Manual Deployment

Create the namespace if it does not already exist (shared with other external model providers):

```sh
oc apply -f manifests/08-external-models/azure-openai/namespace.yaml
```

Create the credential Secret (never stored in manifests):

**RHAIE Version: 3.5, 3.6**


```sh
oc create secret generic azure-openai-api-key \
    --from-literal=api-key="$AZURE_OPENAI_API_KEY" \
    -n external-models \
    --dry-run=client -o yaml | oc apply -f -

oc label secret azure-openai-api-key -n external-models \
    inference.llm-d.ai/ipp-managed=true --overwrite
```


**RHAIE Version: 3.4**


```sh
oc create secret generic azure-openai-api-key \
    --from-literal=api-key="$AZURE_OPENAI_API_KEY" \
    -n external-models \
    --dry-run=client -o yaml | oc apply -f -

oc label secret azure-openai-api-key -n external-models \
    inference.networking.k8s.io/bbr-managed=true --overwrite
```


Apply the external model and MaaS governance resources:

**RHAIE Version: 3.5, 3.6**


```sh
oc apply -k manifests/08-external-models/azure-openai/model/
oc apply -k manifests/08-external-models/azure-openai/maas/
```

The ExternalProvider and ExternalModel CRs:

```yaml
apiVersion: inference.opendatahub.io/v1alpha1
kind: ExternalProvider
metadata:
  name: azure-openai
  namespace: external-models
spec:
  provider: azure-openai
  endpoint: <your-resource>.openai.azure.com
  auth:
    type: apikey
    secretRef:
      name: azure-openai-api-key
---
apiVersion: inference.opendatahub.io/v1alpha1
kind: ExternalModel
metadata:
  name: azure-gpt-4-1-mini
  namespace: external-models
spec:
  modelName: azure-gpt-4-1-mini
  externalProviderRefs:
    - ref:
        name: azure-openai
      targetModel: gpt-4-1-mini
      apiFormat: openai-chat
      path: /openai/deployments/gpt-4-1-mini/chat/completions?api-version=2025-04-01-preview
```


**RHAIE Version: 3.4**


```sh
oc apply -f manifests/08-external-models/azure-openai/model/external-model-34.yaml
oc apply -k manifests/08-external-models/azure-openai/maas/
```

The ExternalModel CR:

```yaml
apiVersion: maas.opendatahub.io/v1alpha1
kind: ExternalModel
metadata:
  name: azure-gpt-4-1-mini
  namespace: external-models
spec:
  provider: azure-openai
  targetModel: gpt-4-1-mini
  endpoint: <your-resource>.openai.azure.com
  credentialRef:
    name: azure-openai-api-key
```


Verify the model reaches Ready:

```sh
oc get maasmodelref azure-gpt-4-1-mini -n external-models
# Expected: PHASE = Ready
```

Test inference:

```sh
MAAS_GW="https://maas.$(oc get ingresses.config/cluster -o jsonpath='{.spec.domain}')"

API_KEY=$(curl -sk -X POST "${MAAS_GW}/maas-api/v1/api-keys" \
    -H "Authorization: Bearer $(oc whoami -t)" \
    -H "Content-Type: application/json" \
    -d '{"name": "azure-openai-test", "subscription": "azure-openai-free", "expiresIn": "1h"}' \
    | python3 -c "import sys,json; print(json.load(sys.stdin)['key'])")

curl -sk "${MAAS_GW}/v1/chat/completions" \
    -H "Authorization: Bearer ${API_KEY}" \
    -H "Content-Type: application/json" \
    -d '{"model": "azure-gpt-4-1-mini", "messages": [{"role": "user", "content": "Say hello in 3 words."}], "max_tokens": 20}'
```

#### Automated Deployment

```sh
./scripts/setup-maas.sh --from-phase 8 \
    --with-external-models \
    --external-model-provider azure-openai \
    --external-model-api-key "$AZURE_OPENAI_API_KEY"
```

## HTTP Proxy {#http-proxy}

Some clusters cannot reach the internet directly and are only allowed to leave through a corporate HTTP/HTTPS proxy. This is common in regulated environments: the OpenShift nodes have no route to `*.openai.azure.com`, but a proxy that accepts `CONNECT` does.

External models still work in this setup, but not through any proxy setting on MaaS. This section explains why, and shows the pattern that does work, using Azure OpenAI as the example.

> [!NOTE]
> Validated on RHOAI 3.5.2, OCP 4.21, Envoy 1.35.10 (OSSM 3.x gateway). The same pattern applies to any external provider, only the hostname changes.

### Why there is no proxy setting

The gateway Envoy is the process that opens the connection to the provider. Nothing in that path reads proxy configuration:

- **`HTTP_PROXY`/`HTTPS_PROXY` do nothing.** Envoy does not read these environment variables, and the cluster-wide `Proxy` CR (`oc get proxy/cluster`) only injects them into pods that honour them. The gateway is not one of them.
- **`DestinationRule` `trafficPolicy.tunnel` cannot be used.** Istio does have native `CONNECT` support, but the API states it applies to TCP or TLS routes and cannot be applied to HTTP routes. The external provider reconciler always generates the `ServiceEntry` with `protocol: HTTPS` (or `HTTP`), which is an HTTP route, so `tunnel` never takes effect.
- **An `EnvoyFilter` using `http_11_proxy` does not work on this Envoy.** On Envoy 1.35 the proxy address must come from per-endpoint `typed_filter_metadata`, and `EnvoyFilter` `MERGE` **appends** repeated fields instead of annotating the generated endpoint, so you cannot attach it to the `STRICT_DNS` cluster Istio builds. The other code path, which takes the address from filter state, is only reachable from compiled-in C++ filters: `Http11ProxyInfoFilterState` has no object factory, so `set_filter_state` cannot populate it. Envoy also documents that extension as having an "unknown security posture".
- **The `maas.opendatahub.io/tls` and `maas.opendatahub.io/port` annotations are RHOAI 3.4 only.** On 3.5 the resources are created by `ipp-external-provider-reconciler`, which ignores them. Annotating the `ExternalProvider` leaves the `ServiceEntry` on `HTTPS`/443 with the `DestinationRule` still in place.

> [!WARNING]
> Do not spend time on `http_11_proxy` EnvoyFilters. It is the suggestion most AI assistants give for this problem and it cannot be made to work against a reconciler-generated cluster on RHOAI 3.5.

### How it works

Instead of teaching the gateway about the proxy, put a small TCP tunnel in front of the proxy and point the mesh at it:

```text
MaaS gateway  --TLS-->  egress-tunnel  --CONNECT-->  corporate proxy  ----->  Azure OpenAI
(openshift-ingress)     (egress-proxy)                                        (TLS ends here)
```

The tunnel accepts the raw TCP that the gateway was going to send to Azure, issues `CONNECT <provider>:443` to the proxy, and splices the bytes through. The important consequence is that **TLS is terminated by Azure, not by the tunnel**: SNI, certificate validation and the `api-key` header injected by IPP all stay end-to-end, and the proxy only sees an opaque tunnel.

It also sends `CONNECT` with a **hostname**, so the proxy does the DNS resolution. That matters because the generated `ServiceEntry` is `resolution: DNS`: if your cluster cannot resolve `*.openai.azure.com`, the Envoy cluster gets zero endpoints and returns 503 before the proxy is ever contacted.

The tunnel is Envoy's `tcp_proxy` with `tunneling_config`, a stable documented feature, and it reuses the `istio-proxyv2` image your gateway already runs, so there is no extra image to mirror and no `anyuid` grant needed.

### Prerequisites

Azure OpenAI already working through MaaS as described in [Azure OpenAI](#azure-openai). Get that green first with direct egress if you can, so that a later failure is clearly the proxy and not the provider.

You also need a proxy that accepts `CONNECT` to the provider hostname on port 443. If you do not have one, or you only want to try this out, the manifests include a lab proxy and Step 1 deploys it for you.

### Step 1: Deploy the proxy

Pick one of the two paths.

**You already have a corporate proxy.** Write down its host and port, you need them in Step 2, and remove the lab proxy from the kustomization so you do not end up with a second proxy in the cluster:

```sh
# edit manifests/08-external-models/http-proxy/kustomization.yaml
# and delete the "- forward-proxy.yaml" line
```

> [!IMPORTANT]
> Removing the file from the kustomization does not remove anything that is already running. `oc apply -k` does not prune. If you tried the lab path before switching to your real proxy, delete the lab proxy explicitly, otherwise it stays in the cluster as an open proxy:

```sh
oc delete deploy/egress-proxy svc/egress-proxy cm/egress-proxy-config \
    -n egress-proxy --ignore-not-found
```

Ask the proxy owners to allow `CONNECT` to your provider hostname on 443. Then go to Step 2.

**You do not have a proxy and want to test.** Keep `forward-proxy.yaml` and deploy it. It is an Envoy that terminates `CONNECT` and logs every tunnel, which is what makes the rest of this section verifiable:

```sh
oc apply -k manifests/08-external-models/http-proxy/
oc rollout status deploy/egress-proxy -n egress-proxy
```

> [!NOTE]
> This same command also deploys the tunnel, because both live in one kustomization. That is fine, the tunnel is configured in Step 2 and restarted there.

Before wiring anything to it, check the proxy on its own. This is the step that tells you whether a later failure is the proxy or the MaaS side, so do not skip it:

```sh
oc run proxytest -n egress-proxy --rm -i --restart=Never \
    --image=registry.access.redhat.com/ubi9/ubi-minimal:latest --command -- \
    curl -sS -o /dev/null -w "http=%{http_code}\n" --max-time 30 \
    -x http://egress-proxy:3128 \
    -H "Content-Type: application/json" \
    -d '{"messages":[{"role":"user","content":"hi"}],"max_tokens":5}' \
    "https://<your-resource>.openai.azure.com/openai/deployments/gpt-4-1-mini/chat/completions?api-version=2025-04-01-preview"
```

You want `http=401`. That looks like a failure but it is the result you need: 401 comes from Azure itself, so the `CONNECT` tunnel opened and TLS completed, and the only thing missing is the API key, which the gateway adds later. A timeout or `http=000` instead means the proxy is not reachable.

> [!TIP]
> `oc run` prints PodSecurity warnings about the throwaway pod. They are harmless, the pod still runs.

The proxy log should show the tunnel for that request:

```sh
oc logs -n egress-proxy deploy/egress-proxy --tail=5 | grep PROXY
```

```text
PROXY method=CONNECT authority=maas-aoai-kfhjq.openai.azure.com:443 upstream=20.232.91.78:443 code=200 flags=DC dur=7
```

That `authority` is exactly what a real corporate proxy has to allow-list.

### Step 2: Configure and deploy the tunnel

The tunnel ships with the values from the test environment, so it is pointing at the wrong provider until you edit it. Open `manifests/08-external-models/http-proxy/egress-tunnel.yaml` and set three things:

- `tunneling_config.hostname` - your own Azure OpenAI resource, for example `my-resource.openai.azure.com:443`.
- the `corporate_proxy` cluster address - the proxy host and port from Step 1. Leave it as the in-cluster Service (`egress-proxy.egress-proxy.svc.cluster.local:3128`) if you deployed the lab proxy.
- `image` - the image your gateway already runs, so there is nothing extra to pull or mirror:

```sh
oc get pod -n openshift-ingress \
    -l gateway.networking.k8s.io/gateway-name=maas-default-gateway \
    -o jsonpath='{.items[0].spec.containers[?(@.name=="istio-proxy")].image}'
```

Apply your edits and restart the tunnel:

```sh
oc apply -k manifests/08-external-models/http-proxy/
oc rollout restart deploy/egress-tunnel -n egress-proxy
oc rollout status deploy/egress-tunnel -n egress-proxy
```

> [!IMPORTANT]
> The restart is not optional. Envoy reads this static configuration once at start-up, so `oc apply` alone updates the ConfigMap while the running pod keeps the old settings. If Step 1 already started the tunnel with the shipped values, only the restart picks up yours. The same applies any time you change the hostname or the proxy address later.

Both pods should be running:

```sh
oc get pods -n egress-proxy
```

### Step 3: Point the ServiceEntry at the tunnel

The reconciler creates the `ServiceEntry` with `resolution: DNS`, which sends the gateway straight to the internet. Switch it to `STATIC` so it resolves to the tunnel instead:

```sh
TUNNEL_IP=$(oc get svc egress-tunnel -n egress-proxy -o jsonpath='{.spec.clusterIP}')

oc patch serviceentry azure-openai -n external-models --type=merge \
    -p "{\"spec\":{\"resolution\":\"STATIC\",\"endpoints\":[{\"address\":\"${TUNNEL_IP}\"}]}}"
```

Nothing else changes. The `ExternalProvider` keeps the real Azure FQDN, so the Host header, SNI and certificate check stay correct.

```sh
oc get serviceentry azure-openai -n external-models -o jsonpath='{.spec}' | python3 -m json.tool
```

> [!WARNING]
> This `ServiceEntry` is owned by `ipp-external-provider-reconciler`. The edit survives a restart of `ai-gateway-operator` and `maas-controller` (verified), because the reconciler creates the resource but does not correct drift. It is still an unmanaged change: re-check it after an RHOAI upgrade, and expect to re-apply it if you delete and recreate the `ExternalProvider`.

### Step 4: Verify

```sh
MAAS_GW="https://$(oc get route maas-default-gateway -n openshift-ingress -o jsonpath='{.spec.host}' 2>/dev/null || echo "maas.$(oc get ingress.config cluster -o jsonpath='{.spec.domain}')")"

API_KEY=$(curl -sk -X POST "${MAAS_GW}/maas-api/v1/api-keys" \
    -H "Authorization: Bearer $(oc whoami -t)" \
    -H "Content-Type: application/json" \
    -d '{"name": "proxy-test", "subscription": "azure-openai-free", "expiresIn": "1h", "ephemeral": true}' \
    | python3 -c "import sys,json; print(json.load(sys.stdin)['key'])")

curl -sk "${MAAS_GW}/v1/chat/completions" \
    -H "Authorization: Bearer ${API_KEY}" \
    -H "Content-Type: application/json" \
    -d '{"model": "azure-gpt-4-1-mini", "messages": [{"role": "user", "content": "Reply with exactly: PROXY OK"}], "max_tokens": 10}'
```

Then confirm the traffic really went through the proxy:

```sh
oc logs -n egress-proxy deploy/egress-tunnel --tail=5 | grep TUNNEL
oc logs -n egress-proxy deploy/egress-proxy  --tail=5 | grep PROXY
```

You should see the gateway pod IP arriving at the tunnel, and a `CONNECT` for your provider hostname in the proxy log:

```text
TUNNEL downstream=10.232.0.2:43124 proxy=172.231.175.184:3128 flags=- dur=22
PROXY method=CONNECT authority=maas-aoai-kfhjq.openai.azure.com:443 upstream=20.232.91.137:443 code=200 flags=DC dur=13
```

Prove there is no direct-egress fallback by breaking the path on purpose. If you deployed the lab proxy, scale it to zero:

```sh
oc scale deploy/egress-proxy -n egress-proxy --replicas=0
```

Inference must then fail with HTTP 503 and `TLS_error ... Connection reset by peer`. With a real corporate proxy you cannot scale it, so stop the tunnel instead, which fails with HTTP 500:

```sh
oc scale deploy/egress-tunnel -n egress-proxy --replicas=0
```

Scale whichever you stopped back to 1 and inference recovers.

> [!IMPORTANT]
> The exact status does not matter, the failure does. If inference still returns 200 while the proxy or the tunnel is down, the gateway is still reaching the provider directly, which means the `ServiceEntry` patch in Step 3 did not take effect and nothing you tested so far went through the proxy.

### Using a real corporate proxy

**Proxy requires authentication.** Envoy's `tunneling_config` can add headers to the `CONNECT` request, so Basic auth works by adding to the `tcp_proxy` config:

```yaml
tunneling_config:
  hostname: "maas-aoai-kfhjq.openai.azure.com:443"
  headers_to_add:
    - header:
        key: "Proxy-Authorization"
        value: "Basic <base64 of user:password>"
```

Keep that value in a Secret and mount it rather than committing it in the ConfigMap.

**Proxy inspects TLS (MITM).** This pattern deliberately does not terminate TLS, so an inspecting proxy breaks certificate validation at the gateway. Either allow-list the provider hostname for pass-through on the proxy, which is the usual answer, or add the proxy's CA to the gateway trust bundle. Pass-through is strongly preferred: the `api-key` is in those requests.

**Proxy only allows certain destinations.** Ask for `CONNECT` to the provider hostname on 443. The lab proxy logs show exactly what to allow-list.

**More than one provider.** `tunneling_config.hostname` is a single fixed destination, so deploy one tunnel Deployment and Service per external provider and patch each `ServiceEntry` to its own tunnel IP.

### Caveats

- One tunnel per provider, as above.
- The tunnel is a single replica in these manifests. Raise `replicas` for anything beyond a demo, it holds no state.
- The `ServiceEntry` edit is unmanaged, see the warning in Step 3.
- Nothing changes for consumers. API keys, `AuthPolicy`, and token rate limiting keep working exactly as before, because only the egress leg moved.

## Known Issues {#known-issues}

### Gemini path incompatibility - RHOAI 3.4 only (RHOAIENG-68592)

On RHOAI 3.4, the BBR `openai` provider hardcodes the upstream path to `/v1/chat/completions`, but Gemini requires `/v1beta/openai/chat/completions`. Inference requests return HTTP 404 from Google's API. Tracked in [RHOAIENG-68592](https://redhat.atlassian.net/browse/RHOAIENG-68592).

**Resolved in RHOAI 3.5+**: the `ExternalModel` CRD includes a `path` field in `externalProviderRefs` that overrides the upstream path. The Gemini manifest sets `path: /v1beta/openai/chat/completions`, and inference works end-to-end.

### WASM auth timeout under load - HTTP 500 (RHOAIENG-71638)

External model calls through the gateway can return HTTP 500 under concurrent load even though the model backend is healthy. The signature: a 23-byte error body, an empty upstream host in the gateway access log, and a response time close to 200ms. This means the Kuadrant WASM plugin timed out waiting for Authorino to authorize the request (default: 200ms, `failureMode: deny`).

The fix is to increase `AUTH_SERVICE_TIMEOUT` on the RHCL operator Subscription. See [Issue 7: WASM Auth Timeout Under Load](/CAI-Field-Manual-MaaS/maas/upgrade/post-upgrade-troubleshooting/#issue-7) in the troubleshooting guide for diagnosis steps and the workaround.

### Anthropic Messages API - no token counting or rate limiting (RHOAIENG-93984)

The MaaS `TokenRateLimitPolicy` only supports the OpenAI-compatible `/v1/chat/completions` endpoint. Requests sent directly to `/v1/messages` (the Anthropic Messages API) bypass token counting and rate limiting entirely - usage is not tracked and rate limits are not enforced. Tracked in [RHOAIENG-93984](https://redhat.atlassian.net/browse/RHOAIENG-93984).

This affects clients that use Anthropic's native API format (e.g., Claude Code with default settings). To ensure token counting works, clients **must** send requests to `/v1/chat/completions` through the MaaS gateway. The BBR `anthropic` provider handles the translation to the Anthropic Messages API upstream.

The upstream fix is tracked in [Kuadrant/kuadrant-operator#1654](https://github.com/Kuadrant/kuadrant-operator/issues/1654).

## Appendix

### Directory Structure

```text
manifests/08-external-models/
  openai/
    kustomization.yaml           # Top-level: namespace + model + maas
    namespace.yaml               # external-models namespace
    model/
      kustomization.yaml         # References 3.5+ manifests (ExternalProvider + ExternalModel)
      external-provider.yaml     # ExternalProvider CR (3.5+)
      external-model.yaml        # ExternalModel CR (3.5+, references provider)
      external-model-34.yaml     # ExternalModel CR (3.4, standalone with credentialRef)
    maas/
      kustomization.yaml
      maas-model.yaml            # MaaSModelRef
      maas-auth-policy.yaml      # MaaSAuthPolicy (system:authenticated)
      maas-subscription.yaml     # MaaSSubscription (10k tokens/hour)
  gemini/
    kustomization.yaml
    namespace.yaml
    model/
      kustomization.yaml
      external-provider.yaml     # ExternalProvider CR (3.5+)
      external-model.yaml        # ExternalModel CR (3.5+)
      external-model-34.yaml     # ExternalModel CR (3.4)
    maas/
      kustomization.yaml
      maas-model.yaml
      maas-auth-policy.yaml
      maas-subscription.yaml
  bedrock/
    kustomization.yaml
    namespace.yaml
    model/
      kustomization.yaml
      external-provider.yaml     # ExternalProvider CR (3.5+)
      external-model.yaml        # ExternalModel CR (3.5+)
      external-model-34.yaml     # ExternalModel CR (3.4)
    maas/
      kustomization.yaml
      maas-model.yaml
      maas-auth-policy.yaml
      maas-subscription.yaml
  anthropic/
    kustomization.yaml
    namespace.yaml
    model/
      kustomization.yaml
      external-provider.yaml     # ExternalProvider CR (3.5+)
      external-model.yaml        # ExternalModel CR (3.5+)
      external-model-34.yaml     # ExternalModel CR (3.4)
    maas/
      kustomization.yaml
      maas-model.yaml
      maas-auth-policy.yaml
      maas-subscription.yaml
  azure-openai/
    kustomization.yaml
    namespace.yaml
    model/
      kustomization.yaml
      external-provider.yaml     # ExternalProvider CR (3.5+)
      external-model.yaml        # ExternalModel CR (3.5+)
      external-model-34.yaml     # ExternalModel CR (3.4)
    maas/
      kustomization.yaml
      maas-model.yaml
      maas-auth-policy.yaml
      maas-subscription.yaml
  http-proxy/
    kustomization.yaml           # namespace + lab proxy + tunnel
    namespace.yaml               # egress-proxy namespace
    forward-proxy.yaml           # LAB ONLY: simulated corporate proxy (CONNECT)
    egress-tunnel.yaml           # TCP tunnel that CONNECTs through the proxy
```

### Supported Providers

The `provider` field in the ExternalModel spec maps to a BBR payload translator. Currently supported values:

- `openai` - OpenAI API (`api.openai.com`)
- `anthropic` - Anthropic API (`api.anthropic.com`)
- `azure-openai` - Azure OpenAI Service
- `bedrock-openai` - AWS Bedrock (OpenAI-compatible)

## References

- [RHOAI 3.5 ExternalProvider documentation](https://docs.redhat.com/en/documentation/red_hat_openshift_ai_self-managed/3.5/html/govern_llm_access_with_models-as-a-service/deploy-and-manage-models-as-a-service#configuring-maas-external-models_maas-deploy)
- [RHOAI 3.4 ExternalModel documentation](https://docs.redhat.com/en/documentation/red_hat_openshift_ai_self-managed/3.4/html/govern_llm_access_with_models-as-a-service/deploy-and-manage-models-as-a-service_maas#configuring-maas-external-models_maas-deploy)
- [BBR (ai-gateway-payload-processing) repository](https://github.com/opendatahub-io/ai-gateway-payload-processing)
- [RHOAIENG-68592 - Gemini BBR path incompatibility](https://redhat.atlassian.net/browse/RHOAIENG-68592)

## Next step

Proceed to [Architecture & Request Flow](/CAI-Field-Manual-MaaS/maas/reference/architecture/).
