# Refresh Token div strong 🔨 In Development — This section is still being developed and may change. Refresh an expired access token using a valid refresh token. This endpoint provides new JWT tokens without requiring full re-authentication. Exchanges a valid refresh token for new JWT access and refresh tokens. Refresh tokens have longer expiration times and allow seamless token renewal. #### Request Body **`refresh_token`** string *required* Valid refresh token obtained from login or previous refresh operation. #### Response **`token`** string New JWT access token. **`device_id`** string Device identifier associated with the token. ## Returns A [Token refresh response object](#token-refresh-response-object) containing new access token and device information. ## Response ```json { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1aWRfYWJjMTIzZGVmNDU2IiwiZXhwIjoxNzM1NjkzNjAwLCJpYXQiOjE3MzU2OTAwMDAsInNjb3BlIjoidXNlciJ9.signature", "device_id": "device-123" } ``` ## Refresh token request ```bash curl -X POST https://api.freddy.aitronos.com/v1/auth/refresh \ -H "Content-Type: application/json" \ -d '{ "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." }' ``` ```python import requests refresh_token = "your_refresh_token_here" response = requests.post( "https://api.freddy.aitronos.com/v1/auth/refresh", headers={"Content-Type": "application/json"}, json={"refresh_token": refresh_token} ) result = response.json() if "token" in result: print("Token refreshed successfully!") new_access_token = result["token"] print(f"New access token: {new_access_token[:50]}...") # Update stored access token else: print("Token refresh failed") ``` ```javascript const refreshToken = localStorage.getItem('refreshToken'); const response = await fetch('https://api.freddy.aitronos.com/v1/auth/refresh', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ refresh_token: refreshToken }) }); const result = await response.json(); if (result.token) { console.log('Token refreshed successfully!'); // Update stored access token localStorage.setItem('accessToken', result.token); // Optionally update refresh token if rotated if (result.refresh_token) { localStorage.setItem('refreshToken', result.refresh_token); } } else { console.error('Token refresh failed'); // Redirect to login if refresh token is also invalid window.location.href = '/login'; } ``` ## Response examples ```json { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1aWRfYWJjMTIzZGVmNDU2IiwiZXhwIjoxNzM1NjkzNjAwLCJpYXQiOjE3MzU2OTAwMDAsInNjb3BlIjoidXNlciJ9.signature", "device_id": "device-123" } ``` ```json { "detail": "Invalid refresh token" } ``` ```json { "detail": "Refresh token has expired" } ```