# API keys

> Read the provider API keys the user saved in the Glassly App.

Source: https://docs.glassly.ai/app-devs/core-concepts/keys/

Users can enter their own provider API keys in the Glassly App under
Settings > Privacy > API Keys. `session.keys` reads them, so a miniapp can call a provider
directly on the user's account instead of shipping a key of its own.

```typescript
const key = await session.keys.get("anthropic");
if (key) {
  // call Anthropic directly with the user's key
}
```

Reading keys needs the `API_KEYS` permission in your
[manifest](https://docs.glassly.ai/app-devs/core-concepts/miniapp-manifest.md). Without it `get()` rejects
with `PERMISSION_NOT_DECLARED`. `session.keys.hasPermission` reports whether you
declared it.

```json miniapp.json
{
  "permissions": [
    { "type": "API_KEYS", "description": "Uses your saved Anthropic key for this feature" }
  ]
}
```

## Readable providers

The phone serves an explicit allowlist. Asking for anything else, including the
Soniox transcription key, rejects with `INVALID_ARGUMENT`.

| `provider` | |
|---|---|
| `"anthropic"` | |
| `"gemini"` | |
| `"openai"` | |
| `"deepseek"` | |
| `"elevenlabs"` | |
| `"mapbox"` | Falls back to the public render token Glassly Cloud serves when the user saved none. `null` only when that's unavailable too. |

## get

| Method | Returns | Notes |
|---|---|---|
| `get(provider)` | `Promise<string \| null>` | `null` when the user hasn't saved a key for that provider. |

Values aren't cached SDK-side. Re-fetch on retry — after a 401 from the
provider, say — to pick up a key the user edited in Settings while your miniapp
was running.

Keys are device-local settings. The value travels only across the local bridge
between the phone and your background context; it never goes through a Glassly
server. Don't log it, persist it in `session.storage`, or forward it to your own
backend.

## When to use this instead of `session.ai`

[`session.ai`](https://docs.glassly.ai/app-devs/core-concepts/ai.md) is the default for LLM work: it needs
no key from the user, the platform pays, and the call stays provider-neutral.
Reach for `session.keys` when you need something `session.ai` deliberately
doesn't cover — streaming, provider-specific server-side tools, or a provider
API that isn't completions at all, such as ElevenLabs voices or Mapbox tiles.
