How to keep model API keys out of JavaScript sent to browsers
Call the model from a server you control. Give browsers a session with your app and keep the inference provider key in server-only configuration.
Example
A prototype reads an inference key in a frontend component. Once built, anyone who downloads the public bundle can inspect the value.
What to do
- Move the provider call to a server endpoint that authenticates the user and validates its input.
- Load the key from server-side configuration. Avoid public environment prefixes, build-time log output and source maps containing secrets.
- Review the deployed bundle, network requests and error bodies using a synthetic build value. Rotate any real key previously included in a release.
How to verify
The browser can use the app, but neither its JavaScript nor its network requests contain the provider key.
Limits
Request redaction cannot remove credentials from JavaScript that has already been published.