> For the complete documentation index, see [llms.txt](https://docs.aidi.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aidi.ai/mosaic/get-started/llm-configuration/byo-api-key.md).

# Bring Your Own API Key

Connect Mosaic to Anthropic, OpenAI, or another supported provider using your own API key.

If you already use Anthropic or OpenAI directly — or you don't have Azure AI Foundry capacity yet — Mosaic accepts an API key from supported providers. Inference is billed by the provider, against your account.

## Supported providers

<table><thead><tr><th width="180">Provider</th><th>Models</th><th>Where to get the key</th></tr></thead><tbody><tr><td><strong>Anthropic</strong></td><td>Claude family (Sonnet, Opus, Haiku)</td><td><a href="https://console.anthropic.com/">console.anthropic.com</a> → API Keys</td></tr><tr><td><strong>OpenAI</strong></td><td>GPT-4, GPT-4o, o1</td><td><a href="https://platform.openai.com/">platform.openai.com</a> → API keys</td></tr></tbody></table>

If you'd rather keep everything in Azure, see [Azure AI Foundry](/mosaic/get-started/llm-configuration/azure-ai-foundry.md) — that's the recommended path for Microsoft-native customers.

## Prerequisites

* An active account with the provider above and an API key with permission to invoke models
* A Tenant Admin account in Mosaic
* A billing setup at the provider — Mosaic does not handle inference billing

## Steps

{% stepper %}
{% step %}
**Create the API key at your provider**

Sign in at the provider and create an API key scoped narrowly:

* Limit it to inference calls only (no admin / billing scopes)
* Set a usage cap — both as a hard limit and a soft alerting threshold
* Tag or name the key `mosaic-prod` so you can identify it later

Copy the key immediately — most providers don't let you view it again after creation.
{% endstep %}

{% step %}
**Connect Mosaic to your provider**

In Mosaic:

1. **Admin → AI Configuration**
2. **Add provider** → choose **Anthropic** or **OpenAI**
3. Paste the **API Key**
4. Pick the **default model** (e.g., `claude-3-5-sonnet-20241022`, `gpt-4o`). Specific recommendations:
   * **Anthropic**: Claude Sonnet for the orchestrator agent; Claude Haiku is fine for cheaper, lower-latency flows
   * **OpenAI**: GPT-4o for the orchestrator; GPT-4o-mini for cheaper flows
5. Click **Test connection** — Mosaic sends a tiny test prompt and verifies the response
6. Click **Save**
   {% endstep %}

{% step %}
**Verify**

Open a Mosaic chat and ask any question. Check **Admin → AI Sessions** — the model name shown should match the one you selected.
{% endstep %}
{% endstepper %}

## Operational tips

### Set a usage cap

Both Anthropic and OpenAI let you set monthly spend caps. Set a hard cap that's higher than your expected usage but well below the worst case. If a runaway agent loop ever happens, the cap stops the bleed.

### Rotate keys periodically

Treat the LLM API key like any other production credential. Rotate quarterly:

1. Create a new key at the provider
2. Update Mosaic with the new key
3. Test
4. Revoke the old key at the provider

Mosaic stores the key encrypted; rotating doesn't invalidate any session history.

### Switching providers

You can change provider at any time in **Admin → AI Configuration**. New chat sessions use the new provider; in-flight sessions complete on the previous one. No data migration is needed; chat history lives in Mosaic regardless of which inference backend ran it.

## When to switch to Azure AI Foundry

If any of these become true, plan a move to Foundry:

* Compliance requires data residency in your Azure tenant
* Your AI usage exceeds direct-API rate limits and you need provisioned throughput
* You want to consolidate AI billing under your existing Azure spend commit

The migration is straightforward — see [Azure AI Foundry](/mosaic/get-started/llm-configuration/azure-ai-foundry.md). No Mosaic-side data needs to move.

## What's next

[Mosaic App Configurations →](/mosaic/get-started/powerbi-configuration/mosaic-app-configurations.md)
