diff --git a/routstr/balance.py b/routstr/balance.py index e0810035..41de5fc8 100644 --- a/routstr/balance.py +++ b/routstr/balance.py @@ -48,7 +48,6 @@ async def get_balance_info(key: ApiKey, session: AsyncSession) -> dict: "balance": billing_key.total_balance, "reserved": billing_key.reserved_balance, "is_child": key.parent_key_hash is not None, - "parent_key": "sk-" + key.parent_key_hash if key.parent_key_hash else None, "total_requests": key.total_requests, "total_spent": key.total_spent, "balance_limit": key.balance_limit, @@ -56,7 +55,9 @@ async def get_balance_info(key: ApiKey, session: AsyncSession) -> dict: "validity_date": key.validity_date, } - if not key.parent_key_hash: + if key.parent_key_hash: + info["parent_key_preview"] = key.parent_key_hash[:8] + "..." + else: # Fetch child keys if this is a parent key statement = select(ApiKey).where(ApiKey.parent_key_hash == key.hashed_key) results = await session.exec(statement) diff --git a/tests/integration/test_child_keys_api.py b/tests/integration/test_child_keys_api.py index 7bfaf2a8..1adb9496 100644 --- a/tests/integration/test_child_keys_api.py +++ b/tests/integration/test_child_keys_api.py @@ -69,9 +69,14 @@ async def test_wallet_info_child_key_no_child_keys( info_response = await integration_client.get("/v1/wallet/info") assert info_response.status_code == 200 info_data = info_response.json() + parent_key = authenticated_client._test_api_key # type: ignore[attr-defined] + parent_key_hash = parent_key.removeprefix("sk-") assert info_data["is_child"] is True assert "child_keys" not in info_data + assert "parent_key" not in info_data + assert info_data["parent_key_preview"] == parent_key_hash[:8] + "..." + assert info_data["parent_key_preview"] not in {parent_key, parent_key_hash} @pytest.mark.integration