Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: bound expires_in_days when creating an API key (#14725)

Vineeth Sai Varikuntlad21d01618cb6
diff --git a/studio/backend/models/auth.py b/studio/backend/models/auth.py
index 71b19834a8e..c619a2d2c11 100644
--- a/studio/backend/models/auth.py
+++ b/studio/backend/models/auth.py
@@ -98,7 +98,10 @@ class CreateApiKeyRequest(BaseModel):
name: str = Field(..., description = "Human-readable label for this key")
expires_in_days: Optional[int] = Field(
- None, description = "Number of days until the key expires (None = never)"
+ None,
+ ge = 1,
+ le = 36500,
+ description = "Number of days until the key expires (None = never)",
)
diff --git a/studio/backend/tests/test_api_key_expiry_inheritance.py b/studio/backend/tests/test_api_key_expiry_inheritance.py
index 3b98abb7960..c0c1730211a 100644
--- a/studio/backend/tests/test_api_key_expiry_inheritance.py
+++ b/studio/backend/tests/test_api_key_expiry_inheritance.py
@@ -90,3 +90,17 @@ def test_a_parent_key_revoked_mid_request_mints_nothing(client, monkeypatch):
assert [row["name"] for row in storage.list_api_keys(storage.DEFAULT_ADMIN_USERNAME)] == [
"parent"
]
+
+
[email protected]("days", [0, -5, 36501, 10**9, 10**12])
+def test_out_of_range_expiry_is_rejected(client, days):
+ raw = _parent(None)
+ response = client.post(
+ "/api/auth/api-keys",
+ headers = {"Authorization": f"Bearer {raw}"},
+ json = {"name": "child", "expires_in_days": days},
+ )
+ assert response.status_code == 422
+ assert [row["name"] for row in storage.list_api_keys(storage.DEFAULT_ADMIN_USERNAME)] == [
+ "parent"
+ ]