Tutorials · 2 min read

Keys

When your token expires, hit refresh and protect your API key

Use refresh tokens to avoid exposing your api credentials when your access token expires.

Erikka Innes

April 21, 2021

If you'd prefer to watch this tutorial, here's a video version (without the Python client):

api.video issues a refresh token alongside an access token. You may have seen this if you've examined the json that comes back when you authenticate with your api key. It looks like this (I edited the access_token and refresh_token a lot, they're very long strings in an actual response):

python

Each access token is good for one hour, then it expires. You have three ways you can deal with this ongoing expiration:

  • Delegated tokens - If you want, you can use delegated tokens for some of your work. Delegated tokens can have any expiration time you want, so you can avoid dealing with the regular expiration. Delegated tokens are only for use with uploads though.
  • Authenticate again - You can use your API key every time your access token expires, and get a new token. Or, you can use it before your access token expires.
  • Use a refresh token - A refresh token lets you get a new access token without exposing your API credentials.

In many situations, using a refresh token will be the best option. When you authenticate, store the refresh token somewhere secure so you can use it later. Today's code sample shows you how to retrieve the refresh token, then use it to get a new token.

python

And that's it! You can continue developing, or continue services in your system that need a new token to complete tasks.

Try out more than 80 features for free

Access all the features for as long as you need.
No commitment or credit card required

Video API, simplified

Fully customizable API to manage everything video. From encoding to delivery, in minutes.

Built for Speed

The fastest video encoding platform. Serve your users globally with 140+ points of presence. 

Let end-users upload videos

Finally, an API that allows your end-users to upload videos and start live streams in a few clicks.

Affordable

Volume discounts and usage-based pricing to ensure you don’t exceed your budget.