Proxy Tokens
Use Proxy Tokens to prevent unauthorized clients from reaching your Endpoints, Servers, and Web Functions. Proxy Tokens can be created in the Dashboard settings or with the modal workspace proxy-tokens CLI.
Authentication models
Endpoints and Servers require authentication by default. To accept public traffic instead, pass --unauthenticated to modal endpoint create or set unauthenticated=True in the @app.server() decorator:
@app.server()
class Private:
...
@app.server(unauthenticated=True)
class Public:
...In contrast, Web Functions are publicly available by default. Enable authentication by setting requires_proxy_auth=True in the fastapi_endpoint, asgi_app, wsgi_app, or web_server decorators:
@app.function()
@modal.fastapi_endpoint()
def public():
return "hello world"
@app.function()
@modal.fastapi_endpoint(requires_proxy_auth=True)
def private():
return "hello friend"The public endpoint can be hit by any client over the Internet:
curl https://public-url--goes-here.modal.runThe private endpoint cannot:
curl --fail-with-body https://private-url--goes-here.modal.run
# modal-http: missing credentials for proxy authorization
# curl: (22) The requested URL returned error: 401
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401Authenticating requests
A Proxy Token comprises a Token ID / Token Secret pair. Requests are authenticated by passing the pair in HTTP headers. They can be sent as separate Modal-Key and Modal-Secret headers:
export TOKEN_ID=wk-1234abcd
export TOKEN_SECRET=ws-1234abcd
curl -H "Modal-Key: $TOKEN_ID" \
-H "Modal-Secret: $TOKEN_SECRET" \
https://private-url--goes-here.modal.runAlternatively, they can be joined with a period (.) and passed as a single Authorization: Bearer header:
export TOKEN_ID=wk-1234abcd
export TOKEN_SECRET=ws-1234abcd
curl -H "Authorization: Bearer $TOKEN_ID.$TOKEN_SECRET" \
https://private-url--goes-here.modal.runThis is the same scheme the OpenAI API uses (Authorization: Bearer <api-key>), so the combined value can be used as the API key in any OpenAI-compatible client or gateway.
Environment scoping
On Workspaces with RBAC enabled, tokens are scoped to specific Environments. See the RBAC guide for more information.