Authentication
Most Plex Media Server API endpoints require an authentication token. This guide explains what Plex tokens are, how to obtain one safely, and how to use and protect them in your integrations.What is a Plex token?
A Plex token is a long-lived credential that proves who you are to Plex services. Two token shapes matter to API developers:
This guide focuses on the server token because it is what you send with every API call to a Plex Media Server.
Before you begin
You will need:- A Plex account.
- Access to a Plex Media Server (your own, or one you have been invited to).
- A way to store secrets securely, such as environment variables or a secrets manager.
Find your server URL
Most local API examples use the server’s LAN address:/library, /status, and most other paths requires one.
Obtain a server token
Option 1: Copy a token from the Plex Web App (fastest for personal scripts)
The Plex Web App already has a valid token for your server. You can copy it from the browser’s network tools:- Open your Plex server in a web browser and sign in.
- Open the browser developer tools and go to the Network tab.
- Refresh a library or perform any action that triggers a request to your server.
- Select a request whose URL points to your server, for example
.../library/sections. - Look for the
X-Plex-Tokenquery parameter or request header. - Copy the token value and store it securely.
Option 2: Request a token from Plex.tv
For applications that cannot open a browser, you can authenticate with Plex.tv and exchange credentials for a token. This requires your Plex username and password and is best done with a small helper script or an OAuth-style sign-in flow. A full example is beyond the scope of this guide; for now, store any Plex.tv token as securely as a server token.Option 3: Use an account setting or claim token
When setting up a new server, Plex uses a short-lived claim token to link the server to your account. Claim tokens expire quickly and are not used for routine API calls. After the server is claimed, use one of the methods above to get a long-lived token.Send the token with each request
Include the token on every request to a protected endpoint. The preferred method is theX-Plex-Token header:
Identify your client
Plex expects API clients to identify themselves with a few extra headers. These headers help server administrators see which clients are connected and help Plex enforce rate limits or compatibility checks. Include them whenever possible:
Example request with identification headers:
X-Plex-Client-Identifier that is stable for the lifetime of your app installation. Generating a new UUID on every restart is fine for experiments, but stable IDs are better for dashboards and automation that run continuously.
Token scope and managed users
The token you use determines what the API can see:- Server owner token — full access to libraries, settings, and sessions.
- Home user token — limited to the libraries and permissions granted by the owner.
- Friend/shared user token — limited to the shared libraries the owner chose.
Environment-variable handling
A minimal, safe pattern is to read the token and server URL from the environment at startup and fail fast if either is missing:.env file loaded by your application, and add .env to .gitignore.
Token rotation
If a token is exposed:- Revoke it by signing the affected device or account out of Plex.
- Generate or copy a new token using one of the methods above.
- Update the token in your secrets manager or environment.
- Restart your integration.
Security best practices
Treat your Plex token like a password. Anyone with the token can act as you on that server.- Never commit tokens to source control. Load them from environment variables or a secrets manager.
- Never expose tokens in public documentation, screenshots, or examples. Use placeholder values such as
<your-token>. - Prefer HTTPS when accessing a server remotely. HTTP is acceptable on trusted local networks, but it sends the token in plain text.
- Rotate tokens if you suspect leakage. You can sign out other devices from your Plex account settings, which invalidates existing tokens.
- Scope tokens by user. When building tools for others, authenticate as that user rather than reusing an owner token.
- Do not log tokens or full request URLs. Redact
X-Plex-Tokenand anyX-Plex-Tokenquery parameter from logs.
Troubleshooting
Next steps
- Follow the Quick Start to make your first authenticated API call.
- Review the API Reference for endpoints that accept the token.
- Read the SDKs page to see how client libraries handle tokens and client identification.