---
updatedAt: 2026-06-12T16:45:46.000Z
agentTools:
  projectIndex: https://docs.hosttools.com/llms.txt
---

# Exchange Token

Exchange an authorization code for access and refresh tokens, or refresh an expired access token.

**Authorization code exchange:** Send `grant_type=authorization_code` with the `code` from the authorize redirect,
along with `redirect_uri`, `client_id`, and `code_verifier` (if PKCE was used).

**Token refresh:** Send `grant_type=refresh_token` with the `refresh_token` and `client_id`.
The old token is revoked and new tokens are issued.

Access tokens expire after 1 hour. Refresh tokens expire after 30 days.


# OpenAPI definition

```json
{
  "openapi": "3.0.0",
  "info": {
    "version": "1.30.0",
    "title": "Host Tools API Reference",
    "description": "Host Tools API. Supports two authentication methods:\n- **Legacy auth token**: Pass the `authToken` header with your user token\n- **OAuth 2.0 Bearer token**: Pass `Authorization: Bearer <token>` header (see OAuth endpoints below)\n\nOAuth 2.0 is recommended for new integrations. It supports granular scopes and automatic token refresh.\n",
    "contact": {
      "name": "Tom Krones",
      "email": "support@hosttools.com",
      "url": "https://hosttools.com"
    }
  },
  "servers": [
    {
      "url": "https://app.hosttools.com"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "OAuth2 Access Token",
        "description": "OAuth 2.0 access token obtained via the authorization code flow"
      },
      "authToken": {
        "type": "apiKey",
        "in": "header",
        "name": "authToken",
        "description": "Legacy user authentication token (UUID)"
      }
    },
    "schemas": {
      "TokenError": {
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Error code per RFC 6749 (invalid_request, invalid_client, invalid_grant, unsupported_grant_type, access_denied)",
            "example": "invalid_grant"
          },
          "error_description": {
            "type": "string",
            "description": "Human-readable error description",
            "example": "Invalid or expired authorization code"
          }
        }
      },
      "TokenRequest": {
        "required": [
          "grant_type",
          "client_id"
        ],
        "properties": {
          "grant_type": {
            "type": "string",
            "description": "The grant type: authorization_code or refresh_token",
            "example": "authorization_code"
          },
          "code": {
            "type": "string",
            "description": "Authorization code (required for grant_type=authorization_code)",
            "example": "a1b2c3d4e5f6..."
          },
          "redirect_uri": {
            "type": "string",
            "description": "Must match the redirect_uri used in the authorize request (required for grant_type=authorization_code)",
            "example": "https://myapp.example.com/callback"
          },
          "client_id": {
            "type": "string",
            "description": "The client_id from registration",
            "example": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
          },
          "client_secret": {
            "type": "string",
            "description": "Client secret (required for confidential clients only)"
          },
          "code_verifier": {
            "type": "string",
            "description": "PKCE code verifier (required if code_challenge was used during authorization)"
          },
          "refresh_token": {
            "type": "string",
            "description": "Refresh token (required for grant_type=refresh_token)"
          }
        }
      },
      "TokenResponse": {
        "required": [
          "access_token",
          "token_type",
          "expires_in",
          "scope"
        ],
        "properties": {
          "access_token": {
            "type": "string",
            "description": "The access token. Use in the Authorization Bearer header.",
            "example": "eyJhbGciOiJIUzI1NiIs..."
          },
          "token_type": {
            "type": "string",
            "description": "Always \"Bearer\"",
            "example": "Bearer"
          },
          "expires_in": {
            "type": "number",
            "description": "Token lifetime in seconds (default 3600 = 1 hour)",
            "example": 3600
          },
          "refresh_token": {
            "type": "string",
            "description": "Refresh token for obtaining new access tokens (valid for 30 days)",
            "example": "dGhpcyBpcyBhIHJlZnJlc2g..."
          },
          "granted_scope": {
            "type": "string",
            "description": "Space-separated list of granted scopes (field name in API is \"scope\")",
            "example": "listings:read reservations:read calendar:read"
          }
        }
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    },
    {
      "authToken": []
    }
  ],
  "paths": {
    "/oauth/token": {
      "post": {
        "summary": "Exchange Token",
        "description": "Exchange an authorization code for access and refresh tokens, or refresh an expired access token.\n\n**Authorization code exchange:** Send `grant_type=authorization_code` with the `code` from the authorize redirect,\nalong with `redirect_uri`, `client_id`, and `code_verifier` (if PKCE was used).\n\n**Token refresh:** Send `grant_type=refresh_token` with the `refresh_token` and `client_id`.\nThe old token is revoked and new tokens are issued.\n\nAccess tokens expire after 1 hour. Refresh tokens expire after 30 days.\n",
        "tags": [
          "OAuth"
        ],
        "requestBody": {
          "description": "Token request",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TokenRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Token response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TokenResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or grant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TokenError"
                }
              }
            }
          },
          "401": {
            "description": "Invalid client credentials",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TokenError"
                }
              }
            }
          }
        }
      }
    }
  }
}
```