Policies let you control who can query your endpoints, how often they can query, and how to track costs. They act as pre and post hooks on endpoint requests, enforcing your rules before returning results. This guide shows you how to configure and manage policies.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/openmined/syft-space/llms.txt
Use this file to discover all available pages before exploring further.
Understanding policy types
Syft Space supports three types of policies:Access policy
Controls who can query your endpoint based on email addresses or domain patterns. Use cases:- Restrict access to specific users or organizations
- Allow public access with exceptions
- Implement allowlists or blocklists
mode- “allow” or “deny”patterns- List of email addresses or regex patterns
Rate limit policy
Limits the number of requests from users over time periods. Use cases:- Prevent abuse and excessive usage
- Implement fair usage policies
- Protect backend services from overload
rate- Request limit in format “count/period” (e.g., “100/m”, “10/s”)- Supported periods:
s(second),m(minute),h(hour),d(day)
Accounting policy
Tracks costs and validates transaction tokens for paid endpoints. Use cases:- Monetize your endpoints
- Track usage costs per user
- Validate prepaid credits
enabled- Whether to enforce accountingrequire_transaction_token- Whether queries must include valid tokens
You can attach multiple policies to a single endpoint. They execute in order: access control → rate limiting → accounting → query processing.
Creating policies
Access policy configuration
Access policies use email patterns to control who can query your endpoint.Allow mode (allowlist)
Only specified users/domains can query:- Only users matching the patterns can query
- Patterns can be exact emails or regex patterns
- Use regex for domain-wide access (e.g.,
.*@company\.com$) - Requests from non-matching users receive 403 Permission Denied
Deny mode (blocklist)
Specified users/domains are blocked from querying:- All users can query except those matching the patterns
- Useful for blocking known abusers while keeping endpoint public
- Patterns can be exact emails or regex patterns
- Matching users receive 403 Permission Denied
Pattern syntax
Exact match:alice@company.com, bob@company.com, etc.
Subdomain wildcard:
alice@eng.company.com, bob@sales.company.com, etc.
Multiple domains:
Rate limit policy configuration
Rate limit policies use the formatcount/period where:
count- Maximum number of requestsperiod- Time window (s, m, h, d)
Examples
100 requests per minute:Rate limit behavior
Per-user tracking:- Rate limits apply per authenticated user (identified by email)
- Each user has their own independent quota
- Counters reset at the end of each time period
- User receives 429 Rate Limited response
- Response includes:
- User must wait until the next time window
Choosing appropriate limits
Generous limits (public endpoints):- 1000/hour or 10,000/day
- Allows legitimate heavy use
- Protects against extreme abuse only
- 100/minute or 1,000/hour
- Balances availability with protection
- Suitable for most use cases
- 10/minute or 100/hour
- Limits expensive operations
- Protects backend resources
- 5/minute or 50/hour
- Prevents runaway test scripts
- Forces developers to implement proper throttling
Accounting policy configuration
Accounting policies track costs and optionally require transaction tokens.Basic cost tracking
Track costs without requiring payment:- Records token usage and costs for each query
- Allows queries without transaction tokens
- Useful for analytics and future billing setup
Paid endpoint with token validation
Require valid transaction tokens for all queries:- Queries must include a valid
transaction_tokenin the request - Token is validated against the accounting system
- Invalid or missing tokens result in 403 Permission Denied
- Token balance is checked and decremented on success
Using transaction tokens
When querying a paid endpoint, include the transaction token:- JWT (JSON Web Token) format
- Contains user credits and authorization
- Issued by the accounting system
- Validated and decremented on each query
Cost calculation
Costs are tracked separately for dataset and model operations: Dataset costs:- Based on search operations
- Typically minimal (vector search is cheap)
- Based on token usage (prompt + completion tokens)
- Varies by model and provider
- Displayed in query response:
Managing policies
Listing policies
View all policies for an endpoint: Endpoint:GET /api/v1/policies?endpoint_id={endpoint_id}
Response:
Updating policies
Modify an existing policy: Endpoint:PATCH /api/v1/policies/{policy_id}
Body:
You can update the name and configuration, but not the policy type or endpoint ID. To change those, create a new policy.
Deleting policies
Remove a policy from an endpoint: Endpoint:DELETE /api/v1/policies/{policy_id}
Policy execution order
When an endpoint has multiple policies, they execute in this order:-
Access policy - Check if user is allowed
- If denied, return 403 immediately
- If allowed, continue to next policy
-
Rate limit policy - Check if user is within limits
- If exceeded, return 429 immediately
- If within limits, increment counter and continue
-
Accounting policy - Validate transaction token
- If required and missing/invalid, return 403 immediately
- If valid, record the request and continue
- Query processing - Execute the actual endpoint query
-
Post-hooks - After query completes
- Accounting policy records actual costs
- Decrements transaction token if applicable
Common policy combinations
Public endpoint with rate limiting
Organization-only endpoint
Paid endpoint with access control
Development endpoint with strict limits
Monitoring and analytics
Track how policies affect your endpoint usage:Policy violations
Monitor when policies block requests:- Access denied (403) - User not allowed
- Rate limited (429) - User exceeded quota
- Insufficient credits (403) - Transaction token invalid
Usage patterns
Analyze legitimate usage to adjust policies:- Peak request times
- Top users by query volume
- Average queries per user
- Cost per user
Policy effectiveness
Evaluate if your policies are working:- Are rate limits too strict? (many 429s from legitimate users)
- Are rate limits too loose? (abuse getting through)
- Is access control configured correctly? (unexpected 403s)
Troubleshooting
Users can’t access endpoint
Symptom: Legitimate users receive 403 Permission Denied Solutions:- Check access policy patterns include the user’s email domain
- Verify regex patterns are correct (test with regex tool)
- Ensure access policy mode is correct (allow vs deny)
- Check if user’s email is verified in their SyftHub account
Rate limits too restrictive
Symptom: Users frequently receive 429 Rate Limited Solutions:- Increase the rate limit (e.g., 100/m → 500/m)
- Use longer time periods for same total (e.g., 100/m → 6000/h)
- Check if a bot or script is making excessive requests
- Consider different limits for different user tiers
Accounting token errors
Symptom: Queries fail with transaction token errors Solutions:- Verify the transaction token is valid and not expired
- Check the token has sufficient balance/credits
- Ensure the token is properly formatted (JWT)
- Verify the accounting system is accessible
Best practices
Start permissive
- Begin with no policies or very generous limits
- Monitor actual usage patterns
- Identify abuse or heavy usage
- Implement targeted restrictions
Layer defenses
- Use multiple policy types together
- Access control filters who can query
- Rate limits protect against abuse from allowed users
- Accounting tracks and limits costs
Test thoroughly
- Test policies with various user emails
- Verify regex patterns match expected inputs
- Test rate limit behavior near the threshold
- Ensure error messages are clear and helpful
Document policies
- Clearly communicate rate limits to users
- Explain access restrictions in endpoint descriptions
- Provide contact info for access requests
- Document pricing and payment requirements
Monitor continuously
- Track policy violations over time
- Identify trends in usage patterns
- Adjust policies based on data
- Be responsive to user feedback
Next steps
Publish to SyftHub
Make your policy-protected endpoint discoverable
Query endpoints
Learn how to query endpoints programmatically