# Client Access Source: https://docs.datawizz.ai/access-control/client-access Enable user-level authentication and authorization with JWT tokens Client Access allows you to validate user access using JWT - creating user level keys with user level rate limits and tracking. This is useful in several scenarios: * **Call LLMs from the Client**: You can call LLMs directly from a web or mobile app, using the user's JWT to authenticate and authorize access. * **Supabase / Firebase Integration**: You can use the user's JWT from Supabase or Firebase to authenticate and authorize access to LLMs. * **User-Level Rate Limits**: You can define rate limits per user, allowing you to control API usage on a per-user basis. * **Organization LLM Access**: You can provide LLM access to users in an organization with personal, tracked & rate-limited keys. ## Getting Started To enable Client Access, create a new project key (in your project settings) and enable the "Client Access" option. You will be required to provide a JWT secret - only JWTs signed with this secret will be accepted. Configure Client Access Now requests to the project key must include a JWT token in the `Authorization` header. The format is `Bearer :` where `` is the project key (starts with `sk-...`) and `` is the signed JWT token. * The JWT will be validated using the configured secret. * If the JWT has issued at (`iat`), not before (`nbf`) or expiration (`exp`) claims, they will be checked to ensure the token is valid. * The JWT must contain a user identifier in one of the following claims: * `sub` (standard JWT subject claim) * `user_id` (custom user ID claim) * `userId` (alternative user ID claim) * If the JWT is valid, the user ID is extracted and used for rate limiting and tracking (this can be combined with user-level rate limits). * The user ID will also be added as a meta tag to the request, allowing you to track usage per user. ## Adding Required Claims You can configure required claims for the JWT in the project key settings. This allows you to enforce specific claims that must be present in the JWT for it to be accepted (for instance, you can require a `tier` claim to control access based on user subscription level). Configure Required Claims ## Supabase Auth Integration If you are using Supabase for authentication, you can easily integrate it with Datawizz client access to manager user access to LLMs. 1. **Get Supabase JWT Secret / Public Key**: you'll need the JWT secret or public key from your Supabase project settings so that Datawizz can validate the JWT tokens issued by Supabase. * Read more in the [Supabase documentation](https://supabase.com/docs/guides/auth/jwts#verifying-a-jwt-from-supabase). Configure Supabase JWT Secret 2. **Enable Client Access**: Create a project key with Client Access enabled. When prompted, enter the Supabase JWT secret or public key from the previous step. 3. **Use Supabase JWT in Requests**: When making requests to Datawizz, include the Supabase JWT in the `Authorization` header as described above. The format is `Bearer :`, where `` is your Datawizz project key and `` is the Supabase JWT token. For example, in a JavaScript application using the Supabase client library, you can get the JWT token like this: ```javascript theme={null} const { data: { session } } = await supabase.auth.getSession(); const jwt = session?.access_token; const client = new OpenAI({ apiKey: `sk-:${jwt}`, baseURL: "https://gw.datawizz.app/**************/openai/v1" }); ``` **Yes, you can do this in the browser!** Datawizz client access is designed to work with client-side applications, allowing you to call LLMs directly from the browser or mobile app using the user's JWT. ## Supported Algorithms Thanks to the `jose` library integration, the system supports multiple JWT signing algorithms: ### HMAC Algorithms (Symmetric) * **HS256**: HMAC with SHA-256 (recommended for simplicity) * **HS384**: HMAC with SHA-384 * **HS512**: HMAC with SHA-512 ### RSA Algorithms (Asymmetric) * **RS256**: RSA with SHA-256 * **RS384**: RSA with SHA-384 * **RS512**: RSA with SHA-512 * **PS256**: RSA-PSS with SHA-256 * **PS384**: RSA-PSS with SHA-384 * **PS512**: RSA-PSS with SHA-512 ### ECDSA Algorithms (Asymmetric) * **ES256**: ECDSA with SHA-256 * **ES384**: ECDSA with SHA-384 * **ES512**: ECDSA with SHA-512 ## Error Responses ### Missing JWT ```http theme={null} HTTP/1.1 401 Unauthorized Content-Type: application/json { "error": "JWT required for this key. Format: key:jwt" } ``` ### Invalid Signature ```http theme={null} HTTP/1.1 401 Unauthorized Content-Type: application/json { "error": "signature verification failed" } ``` ### Expired Token ```http theme={null} HTTP/1.1 401 Unauthorized Content-Type: application/json { "error": "\"exp\" claim timestamp check failed" } ``` ### Missing Required Claim ```http theme={null} HTTP/1.1 401 Unauthorized Content-Type: application/json { "error": "Missing required claim: role" } ``` ### Invalid Claim Value ```http theme={null} HTTP/1.1 401 Unauthorized Content-Type: application/json { "error": "Invalid value for claim role. Got: user" } ``` ### Missing User Identifier ```http theme={null} HTTP/1.1 401 Unauthorized Content-Type: application/json { "error": "JWT must contain user identifier (sub, user_id, or userId claim)" } ``` # Rate Limits Source: https://docs.datawizz.ai/access-control/rate-limits Control API usage with fine-grained rate limits for keys and users # Rate Limits Rate limits provide fine-grained control over API usage, allowing you to prevent abuse and manage resource consumption effectively. The system supports both key-level and user-level limits with multiple resolution types. ## Overview Rate limits in the Datawizz AI Gateway offer: * **Key-level limits**: Apply to the entire API key regardless of user * **User-level limits**: Apply per individual user (requires Client Access with JWT) * **Multiple resolutions**: MINUTE, HOUR, DAY, MONTH * **Multiple limit types**: REQUESTS\_LIMIT, TOKENS\_LIMIT * **Parallel enforcement**: All configured limits are checked simultaneously ## Configuring Rate Limits Rate limits are managed at the Project Key level - so you can set different limits for different keys (e.g. production key can have different limits than development key). Configure Rate Limits To add a rate limit to a key: 1. Go to the **Settings** page of your project. 2. Select the key you want to configure. 3. Click on **Add Rate Limit**. 4. Configure the limit type, resolution, and value. 5. Save the changes. The limit will be applied immediately and enforced on all requests using that key. The system collects usage metrics even before you configure rate limits. So when adding a rate limit, it'll take into account all historical usage data. ## Limit Types ### Request Limits Controls the number of API requests that can be made within a time window. **Example**: 100 requests per hour * Tracks each API call as 1 request * Useful for preventing API abuse and managing load ### Token Limits Controls the total number of tokens (input + output) consumed within a time window. **Example**: 10,000 tokens per day * Tracks actual LLM token usage * Useful for cost control and resource management ## Resolution Types Usage tracking is aligned to clock and calendar time -- so an hourly limit resets every hour, a daily limit resets at midnight (UTC), and a monthly limit resets at the start of each month. The system supports the following resolutions: | Resolution | Description | Use Case | | ---------- | ----------------- | ---------------------------------------- | | `MINUTE` | Per-minute limits | Burst protection, real-time applications | | `HOUR` | Per-hour limits | Standard API rate limiting | | `DAY` | Per-day limits | Daily usage quotas | | `MONTH` | Per-month limits | Billing period controls | ## Rate Limit Levels ### Key-Level Limits Apply to the entire API key, regardless of which user makes the request. **Use cases:** * Overall API key quotas * Preventing single key abuse * Basic rate limiting for simple use cases ### User-Level Limits Apply individually to each user identified via JWT (requires Client Access enabled). **Use cases:** * Per-user quotas in multi-tenant applications * Fair usage across different users * Individual user billing controls **Requirements:** * When using a project key without Client Access, you must pass a User ID in the request metadat (`{"user": ""}`). * When using a project key with Client Access, the User ID is extracted from the JWT claims: * `sub` (standard claim) * `user_id` (custom claim) * `userId` (custom claim) ## Rate Limit Enforcement ### Parallel Checking All configured rate limits are checked simultaneously. **If ANY limit is exceeded, the request is blocked.** **Example scenario:** ``` Configured limits: - Key-level: 1,000 requests per hour - User-level: 100 requests per hour If user has made 99 requests this hour: - User limit: 99/100 ✅ (allowed) - Key limit: 850/1,000 ✅ (allowed) - Result: Request allowed If user has made 100 requests this hour: - User limit: 100/100 ❌ (exceeded) - Key limit: 851/1,000 ✅ (allowed) - Result: Request blocked (429 status) ``` ### Response Headers Rate limit information is included in response headers: ```http theme={null} X-RateLimit-Requests-HOUR-Limit: 100 X-RateLimit-Requests-HOUR-Remaining: 73 X-RateLimit-Tokens-DAY-Limit: 10000 X-RateLimit-Tokens-DAY-Remaining: 8547 ``` **Header format**: `X-RateLimit-{TYPE}-{RESOLUTION}-{Limit|Remaining}` ## Usage Tracking The system proactively tracks usage across **ALL** possible combinations to enable flexible rate limit configuration: ### Key-Level Tracking Always tracks 8 combinations for every request: * REQUESTS\_LIMIT: MINUTE, HOUR, DAY, MONTH (4 entries) * TOKENS\_LIMIT: MINUTE, HOUR, DAY, MONTH (4 entries) ### User-Level Tracking When JWT user ID is present, tracks additional 8 combinations: * Same 8 combinations but scoped to the specific user * **Total: 16 KV entries per request** (8 key + 8 user) **Benefits:** * Add new rate limits anytime with historical data already available * Flexible configuration changes without losing tracking history * Supports complex rate limiting scenarios ## Known Limitations ### Header Collisions When multiple rate limits have the same type and resolution, response headers will collide: **Problematic configuration:** ``` - Key-level: 100 REQUESTS per HOUR - User-level: 50 REQUESTS per HOUR ``` **Result:** * Both limits are enforced correctly ✅ * Headers only show the last processed limit ❌ * Client sees: `X-RateLimit-Requests-HOUR-Limit: 50` (user-level) * Client doesn't see key-level limit headers **Workarounds:** * Use different resolutions (HOUR vs DAY) * Use different types (REQUESTS vs TOKENS) * Be aware that enforcement works correctly despite header visibility issues ## Error Responses ### Rate Limit Exceeded ```http theme={null} HTTP/1.1 429 Too Many Requests Content-Type: application/json X-RateLimit-Requests-HOUR-Limit: 100 X-RateLimit-Requests-HOUR-Remaining: 0 { "error": "Rate limit exceeded: 100 requests per hour" } ``` ## Troubleshooting ### Common Issues **Rate limits not working:** * Verify rate limits are properly configured and enabled * Check that project key has rate limits associated * Ensure usage tracking KV store is accessible **Unexpected rate limit blocks:** * Check if multiple limits are configured (all must pass) * Verify user-level limits if Client Access is enabled * Review recent usage patterns and current limit values **Missing rate limit headers:** * May indicate header collision with multiple same-type limits * Check rate limit configuration for duplicates * Enforcement still works even if headers are missing **User-level limits not working:** * Verify Client Access is enabled on the project key * Ensure JWT contains valid user identifier (`sub`, `user_id`, or `userId`) * Check that JWT is properly signed and validated # Virtual Keys Source: https://docs.datawizz.ai/access-control/virtual-keys Manage access to AI models and track usage across applications Datawizz let's you create "virtual keys" to manage access to AI models and track AI usage across different applications or environments. Datawizz Virtual Keys operate at two levels: * **Key Based Access**: lets you create an API key for an application or environment (`sk-`). * **Client Key Access**: lets you define user-level access controls. The API key is combined with a signed JWT token. Lets you define per-user rate limits, and use JWT claims to control access to specific models or features. Keys are managed at the Project level, and can have global access to all endpoints in a project or fine-grained access to specific models or features. ## Key Based Access Key Based Access is the simplest way to use Datawizz. You create an API key that can be used by any application or environment. This key can be used to access all models and features available to the key. To administer keys, go to the **Settings** page of your project where you will see a list of existing keys and options to create new ones. ## Client Key Access Client Key Access allows you to create API keys that are combined with a signed JWT token. This enables you to define user-level access controls and rate limits. These keys are meant to be publishabled, so they don't work on their own, but only when combined with a JWT token signed with a secret key. Leard more about [Client Access](../client-access). ## Limiting Endpoint Access By default, keys have access to all endpoints in a project. You can limit access to specific endpoints by configuring the key's permissions. When expanding the key details, you will see the "Allowed Endpoints" section. Here you can select which endpoints the key has access to. This allows you to create keys that are limited to specific models or features. Configure Allowed Endpoints # Training Apple Foundation Model Adapters Source: https://docs.datawizz.ai/afm/apple-foundation-model-adapters Train, evaluate and deploy custom adapter for the Apple Foundation Model for on-device inference.