# Get Access Token

<EndpointPage
  breadcrumbs={[
    { label: "REST APIs", href: "/rest-api/rest-api" },
    { label: "Common", href: "/rest-api/rest-api#common" },
    { label: "OAuth", href: "/rest-api/common/oauth" },
    { label: "Get Access Token" },
  ]}
  title="Get Access Token"
  method="POST"
  url="https://exchange.gemini.com/auth/token"
  description="Once you have received an authorization code from the Authorization Request, you can exchange it for access and refresh tokens. Access tokens are short-lived (24 hour expiration) and are used as authentication against Gemini APIs, while refresh tokens never expire and are used to regenerate access tokens."
  example={{
    request: {
      method: "POST",
      url: "https://exchange.gemini.com/auth/token",
      headers: [],
      body: {
        client_id: "my_id",
        client_secret: "my_secret",
        code: "90123465-86ee-44ef-b4e3-835cc89bc8a3",
        redirect_uri: "www.example.com/redirect",
        grant_type: "authorization_code",
      },
    },
  }}
  sections={[
    {
      heading: "Request Body",
      children: (
        <ParamList
          exampleCode={`{\n  "client_id": "my_id",\n  "client_secret": "my_secret",\n  "code": "90123465-86ee-44ef-b4e3-835cc89bc8a3",\n  "redirect_uri": "www.example.com/redirect",\n  "grant_type": "authorization_code"\n}`}
          exampleLabel="Example request body"
          params={[
            {
              name: "client_id",
              type: "string",
              required: true,
              description: <>Unique ID of your application. This is provided in your <a href="https://exchange.gemini.com/settings/api" style={{ color: "inherit", textDecorationLine: "underline" }}>API settings</a>.</>,
            },
            {
              name: "client_secret",
              type: "string",
              required: true,
              description: <>Secret of your application. This is provided when you first register an app in <a href="https://exchange.gemini.com/settings/api" style={{ color: "inherit", textDecorationLine: "underline" }}>API settings</a>.</>,
            },
            {
              name: "code",
              type: "string",
              required: true,
              description: "The authorization code received from the Authorization Request.",
            },
            {
              name: "redirect_uri",
              type: "string",
              required: true,
              description: "Must match the redirect_uri provided in the Authorization Request.",
            },
            {
              name: "grant_type",
              type: "string",
              required: true,
              description: 'The literal string "authorization_code".',
              example: "authorization_code",
            },
          ]}
        />
      ),
    },
    {
      heading: "Responses",
      children: (
        <ResponsesSection tabs={[
          {
            code: "200",
            description: "Access and refresh tokens successfully issued",
            params: [
              { name: "access_token", type: "string", description: "A short-lived token to use in API call authentication. Valid until the expires_in time reaches 0." },
              { name: "refresh_token", type: "string", description: "A refresh token to be used to generate new access tokens." },
              { name: "token_type", type: "string", description: 'The literal string "Bearer".' },
              { name: "scope", type: "string", description: "The OAuth scopes the access token will have access to." },
              { name: "expires_in", type: "integer", description: "The lifetime in seconds of the access token, as measured from the current time." },
            ],
            example: `{\n  "access_token": "d9af2411-3e85-41bb-89f4-cf53750f04df",\n  "refresh_token": "215c5a89-6df7-457b-ba0b-70695da8c91f",\n  "token_type": "Bearer",\n  "scope": "balances:read,orders:create",\n  "expires_in": 86399\n}`,
          },
          { code: "400", description: "Bad request - malformed request or invalid parameters", params: [{ name: "result", type: "string", description: "Error" }, { name: "reason", type: "string", description: "A short description" }, { name: "message", type: "string", description: "Detailed error message" }], example: `{\n  "result": "error",\n  "reason": "InvalidSignature",\n  "message": "Invalid signature for this request"\n}` },
          { code: "401", description: "Unauthorized - missing or invalid authentication", params: [{ name: "result", type: "string", description: "Error" }, { name: "reason", type: "string", description: "A short description" }, { name: "message", type: "string", description: "Detailed error message" }], example: `{\n  "result": "error",\n  "reason": "MissingApikeyHeader",\n  "message": "Must provide 'X-GEMINI-APIKEY' header"\n}` },
          { code: "403", description: "API key fails IP filtering check", params: [{ name: "result", type: "string", description: "Error" }, { name: "reason", type: "string", description: "A short description" }, { name: "message", type: "string", description: "Detailed error message" }], example: `{\n  "result": "error",\n  "reason": "ApiKeyIpFilteringFailure",\n  "message": "ApiKey fails IP Filtering Check for some accounts"\n}` },
          { code: "404", description: "Resource not found", params: [{ name: "result", type: "string", description: "Error" }, { name: "reason", type: "string", description: "A short description" }, { name: "message", type: "string", description: "Detailed error message" }], example: `{\n  "result": "error",\n  "reason": "EndpointNotFound",\n  "message": "API entry point not found"\n}` },
          { code: "429", description: "Too many requests - you have exceeded the rate limit", params: [{ name: "result", type: "string", description: "Error" }, { name: "reason", type: "string", description: "A short description" }, { name: "message", type: "string", description: "Detailed error message" }], example: `{\n  "result": "error",\n  "reason": "Too Many Requests",\n  "message": "Too Many Requests"\n}` },
          { code: "500", description: "Internal server error", params: [{ name: "result", type: "string", description: "Error" }, { name: "reason", type: "string", description: "A short description" }, { name: "message", type: "string", description: "Detailed error message" }], example: `{\n  "result": "error",\n  "reason": "Internal Server Error",\n  "message": "Unexpected server error occurred."\n}` },
        ]} />
      ),
    },
  ]}
/>

<PageNavigation
  prev={{ label: "Authorization Request", href: "/rest-api/common/oauth/authorization-request" }}
  next={{ label: "Refresh Access Token", href: "/rest-api/common/oauth/refresh-access-token" }}
/>
