# Key security best practices

> Keep Wayline API keys safe — call from your backend, restrict browser keys by origin, never ship keys in mobile apps, and rotate exposed keys.

Source: https://www.wayline.cloud/docs/concepts/key-security

API keys grant access to billable usage. Treat live keys like passwords.

## Call the API from your server

The safest pattern is: **your app → your backend → Wayline**. Your backend holds the key, adds caching and per-user limits, and can change providers without an app release.

## Browser keys: restrict by origin

If you must call Wayline directly from a web page, create a **separate key** restricted to your exact origins (for example `https://app.yourcompany.com` or `https://*.yourcompany.com`). Requests from other origins receive `KEY_NOT_ALLOWED_FROM_ORIGIN`. Also restrict its scopes to only the endpoints the page uses and set a spend limit.

An origin restriction stops other websites from using your key in a browser, but anyone can still copy the key and call the API from a script that forges headers. Keep browser keys low-privilege and monitor their usage.

## Never ship keys in mobile apps

Keys inside iOS, Android or Flutter apps can be extracted from the binary. Route mobile traffic through your backend. Our [Flutter recipe](/docs/guides/recipes#flutter-app--your-backend--wayline) shows the pattern.

## Server keys: restrict by IP

For server-to-server use, restrict live keys to your egress IP ranges (CIDR). Requests from elsewhere receive `KEY_NOT_ALLOWED_FROM_IP`.

## Other practices

- Keep keys in a secrets manager or environment variables — never in source control.
- Use different keys per environment and per service, so you can revoke one without an outage.
- Turn on a monthly spend limit.
- Never log full keys. Our SDKs never log keys.
- If a key leaks, [rotate it](/docs/concepts/authentication#rotating-a-key) immediately.
