---
title: Generate access token
slug: payment/v0FH-generate-access-token
description: Learn how to authenticate and retrieve a token for initiating a payment using the `/auth` endpoint with this helpful document. Includes a Curl command example, request details, and expected response code. Get the access token you need for seamless payment
docTags: 
createdAt: 2023-05-18T20:20:44.000Z
---

:::ApiMethodV2
```json
{
  "name": "auth",
  "method": "POST",
  "url": "https://api-sandbox.klavi.ai/payment/customer/v1/auth",
  "description": "Use /auth endpoint by credentials to return a token and continue your process to initiate a payment.",
  "tab": "examples",
  "examples": {
    "languages": [
      {
        "id": "y2z3hBOcZebOQB1YAXsL5",
        "language": "curl",
        "code": "curl --location 'https://api-sandbox.klavi.ai/payment/customer/v1/auth' \\\n--header 'Accept: application/json' \\\n--header 'Content-Type: application/json' \\\n--data '{\"accessKey\":\"string\",\"secretKey\":\"string\"}'",
        "customLabel": ""
      },
      {
        "id": "hVJvbAW8AunbEgLIT0rYf",
        "language": "nodejs",
        "code": "var request = require('request');\nvar options = {\n   'method': 'POST',\n   'url': 'https://api-sandbox.klavi.ai/payment/customer/v1/auth',\n   'headers': {\n      'Accept': 'application/json',\n      'Content-Type': 'application/json'\n   },\n   body: JSON.stringify({\n      \"accessKey\": \"string\",\n      \"secretKey\": \"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": "sgPzMN2d9BschGGyTPx7f",
        "language": "javascript",
        "code": "var myHeaders = new Headers();\nmyHeaders.append(\"Accept\", \"application/json\");\nmyHeaders.append(\"Content-Type\", \"application/json\");\n\nvar raw = JSON.stringify({\n   \"accessKey\": \"string\",\n   \"secretKey\": \"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/payment/customer/v1/auth\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));",
        "customLabel": ""
      },
      {
        "id": "gru7VoINei2Qd1UcS9vEp",
        "language": "python",
        "code": "import requests\nimport json\n\nurl = \"https://api-sandbox.klavi.ai/payment/customer/v1/auth\"\n\npayload = json.dumps({\n   \"accessKey\": \"string\",\n   \"secretKey\": \"string\"\n})\nheaders = {\n   'Accept': 'application/json',\n   'Content-Type': 'application/json'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n",
        "customLabel": ""
      },
      {
        "id": "SwgbY1WM1u4Qi2OXR15t6",
        "language": "ruby",
        "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://api-sandbox.klavi.ai/payment/customer/v1/auth\")\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/json\"\nrequest.body = JSON.dump({\n   \"accessKey\": \"string\",\n   \"secretKey\": \"string\"\n})\n\nresponse = https.request(request)\nputs response.read_body\n",
        "customLabel": ""
      }
    ],
    "selectedLanguageId": "y2z3hBOcZebOQB1YAXsL5"
  },
  "results": {
    "languages": [
      {
        "id": "gBNsrQ_MD6biIRYURWO-9",
        "language": "200",
        "customLabel": "",
        "code": "{\n    \"accessToken\": \"1NiIsInR5cCI6IkpXVCJ9.TlUiXX1fQ.I7XIKNQxVdchh8Mkr6lV\",\n    \"expireAt\": 1752053847\n}"
      }
    ],
    "selectedLanguageId": "gBNsrQ_MD6biIRYURWO-9"
  },
  "request": {
    "pathParameters": [],
    "queryParameters": [],
    "headerParameters": [],
    "bodyDataParameters": [
      {
        "name": "accessKey",
        "kind": "required",
        "type": "string",
        "description": "Pre-generated by Klavi for partner"
      },
      {
        "name": "secretKey",
        "kind": "required",
        "type": "string",
        "description": "Pre-generated by Klavi for partner",
        "children": []
      }
    ],
    "formDataParameters": []
  },
  "currentNewParameter": {
    "label": "Body Parameter",
    "value": "bodyDataParameters"
  },
  "response": [
    {
      "name": "accessToken",
      "kind": "optional",
      "type": "string",
      "description": "Access token"
    },
    {
      "name": "expireAt",
      "kind": "optional",
      "type": "number",
      "description": "Expire time stamp(UTC)",
      "children": []
    }
  ],
  "autoGeneratedAnchorSlug": "auth",
  "legacyHash": "R3T-vTvXg14Y3qE5E7DaL"
}
```
:::

[​](https://docs.klavipay.ai/docs/api-reference/customer/auth/authentication#code-200)

