The SDK supports two authentication modes. Pick the one that matches your use case:Documentation Index
Fetch the complete documentation index at: https://docs.sdk.anghami.com/llms.txt
Use this file to discover all available pages before exploring further.
| Mode | Header | Use when |
|---|---|---|
| API Key | x-api-key: ang_live_... | Server-to-server. Catalog browsing, no user context. |
| OAuth 2.0 + PKCE | Authorization: Bearer <token> | Client apps acting on behalf of a user. Required for library, playlists, and stream acquisition. |
API key
API keys are managed via the Developer Portal and the underlyingDeveloperService. Keys carry a visible prefix (ang_live_... for production, ang_test_... for test) plus an opaque secret tail. Pass the full key in the x-api-key header:
RotateApiKey (the old key keeps working for a server-defined grace period to allow migration). Revoke immediately with RevokeApiKey — there is no recovery.
OAuth 2.0 + PKCE
User-scoped access uses the standard Authorization Code + PKCE flow. PKCE is required for both confidential and public clients.1. Build the authorization URL
code_verifier (43–128 chars, URL-safe) and derive code_challenge = BASE64URL(SHA256(code_verifier)).
2. Exchange the code for tokens
After consent, the user is redirected back to yourredirect_uri with ?code=...&state=.... Exchange via AuthService.ExchangeToken:
access_token, refresh_token, expires_in, and granted scope.
3. Use the access token
4. Refresh
Whenexpires_in runs out, call RefreshToken. Refresh tokens may rotate — always persist the latest one.
Revoking
AuthService.RevokeToken invalidates an access or refresh token immediately. Use this on user logout.
Scopes
See OAuth Scopes for the full list. The current scopes are intentionally broad:read— catalog, search, browse, library, playlists, profile.stream— billable. Required forAcquireMusicStreamandAcquireVideoStream.
write scope is reserved for library and playlist mutations; today the catalog write surface is limited to API key management via DeveloperService.
Errors
Auth failures returnError with code = ERROR_CODE_UNAUTHENTICATED (missing/invalid credential) or ERROR_CODE_PERMISSION_DENIED (valid credential, missing scope). Inspect the message for context.