BYOK

Your customers' keys.
Your encryption. Their isolation.

Neureus BYOK lets your customers provide their own OpenAI, Anthropic, or Gemini API keys. Keys are encrypted at rest with AES-GCM per tenant, isolated by tenant_id at the database level, and rotatable without downtime.

Security model

🔐

AES-GCM encryption

Every key is encrypted at rest using AES-GCM with a per-tenant Data Encryption Key (DEK). Plaintext keys never touch persistent storage. The DEK is stored separately — compromise of the database doesn't expose keys.

🏢

Tenant isolation

Keys live in nr_tenant_provider_keys — filtered by tenant_id on every read. One tenant's keys are structurally inaccessible to another, even if they share infrastructure.

🔄

Zero-downtime rotation

POST /ai/providers/:provider/rotate re-encrypts the key under a new DEK. During rotation, the old key continues serving traffic. Rotation is atomic — no gap in availability.

How it works

1

Your customer provides their key

Via your settings UI, your customer enters their OpenAI API key. Your app calls the Neureus BYOK endpoint with the key and the tenant's Bearer token.

2

Neureus encrypts and stores it

Neureus generates a per-tenant DEK, encrypts the key with AES-GCM, and stores the ciphertext in nr_tenant_provider_keys. The DEK is stored in KV with the tenant's namespace — separate from the D1 record.

3

Calls use the customer's key automatically

When a tenant calls /ai/chat with model gpt-4o, Neureus decrypts their stored OpenAI key and uses it for the provider call. The global OPENAI_API_KEY Wrangler secret is the fallback when no BYOK key exists for that provider.

4

Billing goes to the customer

Provider calls are made with the customer's key — they see the charges in their own OpenAI/Anthropic dashboard. You never see their usage or pay their token costs.

BYOK API

PUT
/ai/providers/:provider

Store a provider key for the calling tenant. :provider is openai, anthropic, or gemini.

curl -X PUT https://app.neureus.ai/ai/providers/openai \
  -H "Authorization: Bearer $TENANT_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "apiKey": "sk-proj-your-openai-key" }'

// Response: { "provider": "openai", "stored": true }
GET
/ai/providers

List configured providers for the calling tenant. Returns provider names and masked key previews — never the full key.

curl https://app.neureus.ai/ai/providers \
  -H "Authorization: Bearer $TENANT_KEY"

// Response:
{
  "providers": [
    { "provider": "openai", "maskedKey": "sk-pr...key", "setAt": "2026-06-20T..." },
    { "provider": "anthropic", "maskedKey": "sk-an...key", "setAt": "2026-06-18T..." }
  ]
}
POST
/ai/providers/:provider/rotate

Re-encrypt the stored key under a new DEK. Zero downtime — the key continues serving traffic during rotation.

curl -X POST https://app.neureus.ai/ai/providers/openai/rotate \
  -H "Authorization: Bearer $TENANT_KEY"

// Response: { "provider": "openai", "rotatedAt": "2026-06-20T..." }
DELETE
/ai/providers/:provider

Remove a stored key. Future calls to that provider will fall back to the global key or return 422 if none exists.

curl -X DELETE https://app.neureus.ai/ai/providers/openai \
  -H "Authorization: Bearer $TENANT_KEY"

// Response: { "provider": "openai", "deleted": true }

TypeScript SDK

import { NeureuAI } from '@neureus/sdk';

// Each customer gets their own tenant client (their API key = their tenant)
const tenantClient = new NeureuAI({ apiKey: customerApiKey });

// Store their OpenAI key — encrypted, isolated to their tenant
await tenantClient.ai.setProviderKey('openai', customerOpenAIKey);

// Now all OpenAI calls from this tenant use their key automatically
const { text } = await tenantClient.ai.chat({
  model: 'gpt-4o',  // Uses the customer's OpenAI key, not yours
  messages: [{ role: 'user', content: 'Hello' }],
});

// List their configured providers (returns masked keys only)
const { providers } = await tenantClient.ai.listProviderKeys();

// Rotate their key (re-encrypts under new DEK, zero downtime)
await tenantClient.ai.rotateProviderKey('openai');

When to use BYOK

SaaS with enterprise customers

Large enterprise customers often have existing OpenAI or Anthropic contracts. BYOK lets them use Neureus without routing tokens through your billing.

White-label AI products

Building a white-label AI tool? Each reseller can provide their own API keys. Their token costs stay on their own accounts — you only charge for the Neureus platform.

Data compliance requirements

Some regulated industries need direct contractual relationships with AI providers. BYOK lets your customers maintain that relationship while using Neureus infrastructure.

Cost transparency

Customers who want full visibility into their AI spend — seeing it in their own provider dashboard — prefer BYOK over opaque per-call billing from you.

BYOK included on all plans

Encrypted per-tenant key storage, rotation, and isolation — no add-on pricing. Start free.