- Create API keys for the TensorZero Gateway
 - Require clients to use these API keys for requests
 - Manage API keys in the TensorZero UI
 
TensorZero supports authentication for the gateway.
Authentication for the UI is coming soon.
In the meantime, we recommend pairing the UI with complementary products like Nginx, OAuth2 Proxy, or Tailscale.
Configure
You can find a complete runnable example of this guide on GitHub.
1
Configure your gateway to require authentication
You can instruct the TensorZero Gateway to require authentication in the configuration:With this setting, every gateway endpoint except for 
tensorzero.toml
/status and /health will require authentication.2
Deploy TensorZero and Postgres
You must set up Postgres to use TensorZero’s authentication features.
Example: Docker Compose
Example: Docker Compose
You can deploy all the requirements using the Docker Compose file below:
docker-compose.yml
3
Create a TensorZero API key
You can create API keys using the TensorZero UI.
If you’re running a standard local deployment, visit Once you’ve created an API key, set the 
http://localhost:4000/api-keys to create a key.Alternatively, you can create API keys programmatically in the CLI using the gateway binary with the --create-api-key flag.
For example:The API key is a secret and should be kept secure.
TENSORZERO_API_KEY environment variable.4
Make an authenticated inference request
- Python (TensorZero SDK)
 - Python (OpenAI SDK)
 - Node (OpenAI SDK)
 - HTTP
 
You can make authenticated requests by setting the 
api_key parameter in your TensorZero client:tensorzero_sdk.py
The client will automatically read the 
TENSORZERO_API_KEY environment variable if you don’t set api_key.Authentication is not supported in the embedded (in-memory) gateway in Python.
Please use the HTTP client with a standalone gateway to make authenticated requests.
5
Manage API keys in the TensorZero UI
You can manage and delete API keys in the TensorZero UI.
If you’re running a standard local deployment, visit 
http://localhost:4000/api-keys to manage your keys.