---
title: Generate Access Token
slug: klaas/generate-access-token
docTags: 
createdAt: 2025-06-27T07:40:18.666Z
---

:::ApiMethodV2
```json
{
  "name": "token",
  "method": "POST",
  "url": "https://api-sandbox.klavi.ai/token",
  "description": "Generate access token",
  "tab": "examples",
  "examples": {
    "languages": [
      {
        "id": "jXzE0Ye-qs75Vjob-IB_t",
        "language": "curl",
        "code": "curl --location 'https://api-sandbox.klavi.ai/token' \\\n--header 'Accept: application/json' \\\n--header 'Content-Type: application/x-www-form-urlencoded' \\\n--data '{\n  \"grant_type\": \"String\",\n  \"scope\": \"String\",\n  \"client_id\": \"String\",\n  \"client_secret\": \"String\"\n}'",
        "customLabel": ""
      },
      {
        "id": "4-T49yPATjDfc1avrSc6z",
        "language": "nodejs",
        "code": "var request = require('request');\nvar options = {\n   'method': 'POST',\n   'url': 'https://api-sandbox.klavi.ai/token',\n   'headers': {\n      'Accept': 'application/json',\n      'Content-Type': 'application/x-www-form-urlencoded'\n   },\n   body: JSON.stringify({\n      \"grant_type\": \"String\",\n      \"scope\": \"String\",\n      \"client_id\": \"String\",\n      \"client_secret\": \"String\"\n   })\n\n};\nrequest(options, function (error, response) {\n   if (error) throw new Error(error);\n   console.log(response.body);\n});\n",
        "customLabel": ""
      },
      {
        "id": "TP_32rY5B15_X-Tjn2sWz",
        "language": "javascript",
        "code": "var myHeaders = new Headers();\nmyHeaders.append(\"Accept\", \"application/json\");\nmyHeaders.append(\"Content-Type\", \"application/x-www-form-urlencoded\");\n\nvar raw = JSON.stringify({\n   \"grant_type\": \"String\",\n   \"scope\": \"String\",\n   \"client_id\": \"String\",\n   \"client_secret\": \"String\"\n});\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"https://api-sandbox.klavi.ai/token\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));",
        "customLabel": ""
      },
      {
        "id": "bKGO0L3da7rxA0LcD0nVR",
        "language": "python",
        "code": "import requests\nimport json\n\nurl = \"https://api-sandbox.klavi.ai/token\"\n\npayload = json.dumps({\n   \"grant_type\": \"String\",\n   \"scope\": \"String\",\n   \"client_id\": \"String\",\n   \"client_secret\": \"String\"\n})\nheaders = {\n   'Accept': 'application/json',\n   'Content-Type': 'application/x-www-form-urlencoded'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n",
        "customLabel": ""
      },
      {
        "id": "trs0UDDLAOQX2EyqQnwUW",
        "language": "ruby",
        "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://api-sandbox.klavi.ai/token\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Post.new(url)\nrequest[\"Accept\"] = \"application/json\"\nrequest[\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nrequest.body = JSON.dump({\n   \"grant_type\": \"String\",\n   \"scope\": \"String\",\n   \"client_id\": \"String\",\n   \"client_secret\": \"String\"\n})\n\nresponse = https.request(request)\nputs response.read_body\n",
        "customLabel": ""
      }
    ],
    "selectedLanguageId": "jXzE0Ye-qs75Vjob-IB_t"
  },
  "results": {
    "languages": [
      {
        "id": "8gliTm36UwbwxHnV0W2xu",
        "language": "200",
        "customLabel": "",
        "code": "{\n  \"access_token\": \"eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJYQnhoZ1NwT0RQZGlJNUFaazNKclppNFNBZGN2SGoybGN2a05mQjFTdzNRIn0.eyJleHAiOjE3NTE1OTk4NzksImlhdCI6MTc1MTU5OTU3OSwianRpIjoiMjQ4MWFiODYtMGNmNC00MzgzLWIyOWQtNWRhMGY3NTYzZTY1IiwiaXNzIjoiaHR0cHM6Ly9tdGxzLWFwaS1zb3Blbi5rbGF2aS5haS9yZWFsbXMvS2xhdmlPQXV0aCIsInN1YiI6IjNlYWMyNmJhLTliN2QtNGYzMi05OTNlLTNjY2JiM2NhZjYxNCIsInR5cCI6IkJlYXJlciIsImF6cCI6IktsYXZpVGVzdCIsImFjciI6InVybjpicmFzaWw6b3BlbmJhbmtpbmc6bG9hMiIsInNjb3BlIjoia2xhYXMiLCJjbGllbnRIb3N0IjoiMTAuMi4xMjguMjE3IiwiY2xpZW50QWRkcmVzcyI6IjEwLjIuMTI4LjIxNyIsImNsaWVudF9pZCI6IktsYXZpVGVzdCJ9.GYABzepeD2exChi_Jsdv8uvwOMfPWNn1TP80ct5dNP6DMh5sjfw3X394g0pLD8iry75QFBVVZ527bUmUl9DHqs6Z32N3a-ex6SMYt9eoM-vTT8CYNRlwpG_RjwXQps05HFchkkH-C48h8POu8EvL5d2f0eFNpgn6lVYz9MDeKPaUKInM6aNxN4UcLff7WrQVSoSzAooVQ5eB_j7lxMnDaZn7KTzvweuWK8b5MR5pZF_OZETS5VH_9XLAZW-Gk5vmlxr_7quJR2IIIHQbkOGU8BFc0Aa8Qm1v75Fa_fdBpOrK6sF3ibgK_ubn4BfPvGwtfoFYgVWbaIoB9WnUgSQDDQ\",\n  \"expires_in\": 300,\n  \"token_type\": \"Bearer\",\n  \"scope\": \"klaas\"\n}"
      }
    ],
    "selectedLanguageId": "8gliTm36UwbwxHnV0W2xu"
  },
  "request": {
    "pathParameters": [],
    "queryParameters": [],
    "headerParameters": [
      {
        "name": "Content-Type",
        "kind": "required",
        "type": "string",
        "description": "Currently only support: 'application/x-www-form-urlencoded'",
        "": "Currently only support: 'application/x-www-form-urlencoded'"
      }
    ],
    "bodyDataParameters": [
      {
        "name": "grant_type",
        "kind": "required",
        "type": "string",
        "description": "Currently only support 'client_credentials'",
        "": "grant_type"
      },
      {
        "name": "scope",
        "kind": "required",
        "type": "string",
        "description": "Currently only support 'klaas'",
        "": "Currently only support 'klaas'"
      },
      {
        "name": "client_id",
        "kind": "required",
        "type": "string",
        "description": "client ID",
        "": "client_id"
      },
      {
        "name": "client_secret",
        "kind": "required",
        "type": "string",
        "description": "Client secret",
        "": "client_secret"
      }
    ],
    "formDataParameters": []
  },
  "currentNewParameter": {
    "label": "Header Parameter",
    "value": "headerParameters"
  },
  "hasTryItOut": false,
  "response": [
    {
      "name": "access_token",
      "kind": "optional",
      "type": "string",
      "description": "Access token"
    },
    {
      "name": "expires_in",
      "kind": "optional",
      "type": "number",
      "description": "Token validity period\nDefault: 300 seconds",
      "children": []
    },
    {
      "name": "token_type",
      "kind": "optional",
      "type": "string",
      "description": "Token type\nDefault value: Bearer",
      "children": []
    },
    {
      "name": "scope",
      "kind": "optional",
      "type": "string",
      "description": "Default value: klaas",
      "children": []
    }
  ]
}
```
:::

