# AI Provider & BYOK (Bring Your Own Key)

_AI Features_

CRMown's AI features run on a shared monthly token budget by default (the CRMown AI, included in your plan), but you can switch to your own provider — Anthropic, OpenAI, Google, Microsoft Azure, AWS Bedrock, Meta Llama, xAI Grok, DeepSeek, Mistral, Cohere, Perplexity, Groq, Alibaba Qwen, or SambaNova. With BYOK, every AI feature in this category routes to your account's API instead of ours, the monthly token cap is removed entirely, and you control the model upgrade schedule.

## Steps
1. Go to Settings > AI Usage > AI Configuration.
2. Pick your provider from the dropdown. The card updates to show which models will be used for each task tier (light / standard / heavy).
3. Paste your API key. It's used only for your org's AI requests.
4. Amazon Bedrock only: paste a Bedrock API key (AWS console → Amazon Bedrock → API keys — NOT an AWS access key/secret) and set the AWS Region where you enabled Nova model access (e.g. us-east-1). Other providers just need their single API key.
5. Click "Test connection" (shown for every provider except the default CRMown AI). It makes one tiny real AI call and reports success — with the model name and latency — or the exact provider error. Always test before relying on a key: a saved-but-untested key can silently fail later as "No response from AI".
6. Click Save. The next AI call (try Ctrl+K with a simple command like "show my contacts") routes through your provider — confirm in Settings > AI Usage > Dashboard, where the model name will reflect your provider.
7. To revert, clear the API key field and Save. AI calls fall back to the shared CRMown AI key under the monthly token cap.

## Tips
- Three task tiers: light (cheap classification + simple extraction — Haiku / gpt-4o-mini / gemini-2.0-flash / etc.), standard (content generation, summaries, analysis — Sonnet / gpt-4o / gemini-2.5-pro / etc.), heavy (complex reasoning + plan compilation for AI Agents — Sonnet / o3 / DeepSeek-R1 / etc.). The training docs for each feature mention which tier they use so you can map to your provider's pricing.
- BYOK orgs have NO monthly token cap — usage is metered by your AI provider, not by CRMown. The "AI quota exhausted" errors don't apply.
- The Settings > AI Usage > Dashboard tracks token consumption by feature regardless of provider, so you can audit which features are driving cost.
- Switching providers mid-month is supported and instant — no migration. New AI calls route to the new provider; in-flight ones finish on the old one.
- Reasoning models (OpenAI o3, DeepSeek R1) work but tier-3-only — they're used for complex AI features (Autonomous AI Agents compilation, Pipeline Coach's deep diagnoses). Light + standard features stay on the standard chat-completion model.

## Example
A 25-person engineering services org has an enterprise AI provider contract at a steep discount via their cloud reseller. They paste their provider API key into Settings > AI Usage > AI Configuration. Their CRMown AI bill drops to $0 (everything routes through their existing provider contract); their dashboard shows the same model tiers they're used to. Their CTO swaps the key for a different provider when they migrate cloud vendors — same UI flow, no feature regression.

## Troubleshooting
- **"BYOK key invalid" error after save** — API key has typos, has been revoked, or was generated for the wrong project / region. Fix: Regenerate a fresh key in your provider's console, paste the full key including any prefix (sk-ant-, sk-, etc.).
- **Switched providers but Settings > AI Usage still shows the previous provider's models** — Either the dashboard is showing historical data (pre-switch calls), or the provider field wasn't updated alongside the key. Fix: Confirm Settings > AI Usage > AI Configuration > Provider dropdown matches the new provider (not just the key). Force a fresh AI call (Ctrl+K). The dashboard will start showing the new provider's models on new entries.
- **Some features work on BYOK, others don't** — A few features (Voice AI, Vision-heavy document analysis on certain providers) require provider-specific capabilities that not all 14 providers support equally. Fix: CRMown AI (the default) supports every feature. Major providers like OpenAI, Google, and Microsoft (Azure) support 95%+. The smaller / open-source providers cover the text-heavy features but may degrade on vision or voice.
- **I selected Amazon Bedrock and every AI surface says "No response from AI"** — Bedrock is not authenticated like the other providers: it needs a Bedrock API key (a bearer token) and the correct AWS region. An AWS access key/secret, or a region where your Nova models aren't enabled, won't connect. Fix: In Settings > AI Usage > AI Configuration: (1) paste a Bedrock API key from AWS console → Amazon Bedrock → API keys, (2) set AWS Region to where you enabled Nova (e.g. us-east-1), (3) click Test connection. Green = working; a red error states exactly what AWS rejected. Make sure model access for Amazon Nova is granted in that region's Bedrock console.

## Error messages
- `AI is not connected. No CRMown API key is configured for this workspace.` — Neither a BYOK key is saved nor is the platform's CRMown AI key set in the environment. Add a key under Settings > AI Usage > AI Configuration, or escalate to the platform admin.
- `AI token limit reached (X / Y tokens this month)` — You're on the shared platform key and hit your plan's monthly cap. Either upgrade plan, wait for the 1st-of-month reset, or add a BYOK key for unlimited usage.
- `<provider> API error (401)` — Your BYOK key is rejected by the provider — usually invalid, revoked, or wrong region. Regenerate and re-save.
- `<provider> API error (429)` — Your BYOK provider rate-limited you. Wait, or upgrade the rate limit on your provider account. Not a CRMown issue.
- `Amazon Bedrock error (403 / AccessDenied)` — Your Bedrock API key is valid but lacks permission for the requested model in that region — usually model access for Amazon Nova hasn't been granted in the Bedrock console for your AWS account/region. Enable model access, or switch to a region where it's enabled, then Test connection.
- `Amazon Bedrock error (400 / inference profile)` — The model must be invoked through a cross-region inference profile for on-demand use. CRMown derives this automatically from your AWS Region — confirm the region matches where your Nova access is enabled.

## Plans
BYOK is available on every plan including Starter — there's no upcharge to bring your own key. The shared platform key is monthly-capped: Starter 500K, Pro 2M, Max 10M, Custom 50M tokens. BYOK = unlimited.
