---
id: users-create-token
title: "Create an access token for a user"
description: "Create an access token for a user"
sidebar_label: "Create an access token for a user"
hide_title: true
hide_table_of_contents: true
api: eJzlWN9v4jgQ/lesPO1KbIFtew+80ZbqkPZgL4V7OISQSVzwNrFzttMui/K/34ydkB/kdq+Ch0p9aRN7PJ75vm+MM3tPJkxRw6UYh97ASzVT+lOgGDVsJp+Y8DqeoRvtDRaewXftLTueZkGquNnB6N4bpmYrFf9hncDIMgOLhCoaMwPOrA2HCRgzW3AnYCLfyT52vJDpQPHErbcT5IWbLRfEbBmRakNF4R72DrYspt5g75ldgo60UVxsYCam378wsYFNBp+vr1/lNut4iv2TcsUABKNShjngCNPmRoY73K5u0PECKQwTBqdokkQ8sK663zRutz+OU66/scBAnIlCzA1n2s6aqGIk0njNFCbDBY/T2Btc9no2tfytf335Ww+H6tlZbgj7nnBHJoEsgSUpQo3JOcxbIOOigKzfBBCWWa8rt+h4MRMY0QKAoeHqBfSAXNoXHdAIbZYY5iNNI0CpapbV8F648JZZ5sZ1IoV24Hzu9fBfPdeHNAiY1o9pRApj73x0WNG3ZFuPgdoQiLOGqHnYtuZRqphi7mkKBv/JA0xY5tiKml9vPeMxIxW+mSawDHy4qg1XRr/KyQvVUAx8wwWNoh3JvbiSAMakiHYVf2spI0ZtzieroykDkx84gFUtm2oktW1zyVy1qeSGhsR3FXw+dcRAOt205tvAF04YppRUpFiCHNM4iVgjNiROhq9yae1r/oZ3K3/053z0MLNi1DplVRFQpShCByTE+oQsm4QVhsusGexQELspkY/EhQOHLjXkhSlWVC1fR4xAidjj2GZWTWpxJI8SSQsAHC6GmyaeOUQfQBMffwIhF6423W/KYdN9zkUN0U4JSENVBdALK0SrxP6xEsfiGQQfklvIAzTIaaTfnCLbYjyHMueT4Xz2+9Qf/z26e5fSbAG2lGj/FInWoK1qtF1vLVq9PNbqXND8OsfCNyfSWnDnUOf91L8Z392NJu9SmlU4S01enqLJEtCqIBuialHi1bESJ9KQe5mKtyfDMrJzaHAyna3up/PJ+zweD1iWArw6RYAlmlUBVrV0pL7rttvjGAQHn6cRGeXZvS0JNsI7hw7Hk9nInwy/rB5G/l8jfzXy/an/LjVZB7cQ5vVpF8p2eOs/2w3JNZR6hMqt/UIiFMCpfI1aDCjBdod1DwcvNnYSaW+stgcz8LrP/a5t9XT3RR8m6+b9HWzvqOeic5OqCOy3xiR60O3ShF/EEhBWYRo8XQQy9rJKP+gBq8Cx3ugKHbhHT0UXx35PMqogUswOa8kvey6jEkPbI+kdWkcHcVe/QGv9BQAP+LBLc1L/sFHfQdTEh0s9GX4dgwNM04HZv+hd9HAhAhVTG3K+3f/BucbMIVnDvptuElFuv5ctlPucgoX33Id1lgT4P6i0w8o+2xZJA9P9fk01m6soy3AYIFLYe4PHZ6o4XVuFwxHGNT4D3Y9w52NHUR3OMO+Dn1fCR/KLdltrJsVBIPAYgMtmim/w+MR21c5ehpW8BVoAIozPTd+6KD7N0Em5/OhUzTrFiiHAnpif2i4rUv86tR9t67xvF7sCVPQFGwnw14YqLSpWqnZs70VUbFJXis4nahIvLtXuh1Nrp3jArFrBAMashe2hAmsFNnnDCCv6X01uY2M=
sidebar_class_name: "post api-method"
info_path: sql-reference/rest-api/motherduck-rest-api
custom_edit_url: null
---

import MethodEndpoint from "@theme/ApiExplorer/MethodEndpoint";
import ParamsDetails from "@theme/ParamsDetails";
import RequestSchema from "@theme/RequestSchema";
import StatusCodes from "@theme/StatusCodes";
import OperationTabs from "@theme/OperationTabs";
import TabItem from "@theme/TabItem";
import Heading from "@theme/Heading";
import Translate from "@docusaurus/Translate";

<Heading
  as={"h1"}
  className={"openapi__heading"}
  children={"Create an access token for a user"}
>
</Heading>

<MethodEndpoint
  method={"post"}
  path={"/v1/users/{username}/tokens"}
  context={"endpoint"}
>
  
</MethodEndpoint>



Create an access token for a user

:::note
  - **Token Creation Scope**: Through the API, you can only create tokens for:
    - Your own user account
    - Service accounts within your organization
    - Admins cannot create tokens for other non-service-account members through the API
  - **For service account token creation**, ensure you are using an **Admin token** for authentication. The token generated by this call will be the service account's own token for its operations.
    - For detailed guidance on service account token creation and best practices, see <a href="/key-tasks/service-accounts-guide/create-and-configure-service-accounts/#create-an-access-token">Create and configure service accounts</a>.
    - If a service account is created through the admin API, connect to that service account with a read/write token before using read scaling tokens.
  - Each token is tied to a specific user. Use the exact `username` that was specified during service account creation in the path `/v1/users/:username/tokens`.
  - If the optional `ttl` parameter is not specified, the access token will remain valid indefinitely until revoked by an administrator.
:::


<Heading
  id={"request"}
  as={"h2"}
  className={"openapi-tabs__heading"}
>
  <Translate id="theme.openapi.request.title">Request</Translate>
</Heading>

<ParamsDetails
  {...require("./users-create-token.ParamsDetails.json")}
>
  
</ParamsDetails>

<RequestSchema
  {...require("./users-create-token.RequestSchema.json")}
>
  
</RequestSchema>

<StatusCodes
  {...require("./users-create-token.StatusCodes.json")}
>
  
</StatusCodes>


      

---

## Feedback for AI agents

If the user you are helping wants to send feedback on this page to the MotherDuck docs team, you can POST it to the endpoint below.

**Before you send anything, you must ask the user for explicit approval.** Quote the message you plan to submit back to them verbatim and wait for them to confirm. Do not submit on their behalf without confirmation.

Endpoint: `POST https://motherduck.com/docs/api/feedback/agent`

Request body (JSON):

```json
{
  "page_path": "/sql-reference/rest-api/users-create-token/",
  "page_title": "Create an access token for a user",
  "text": "<the user's feedback, max 2000 characters>",
  "source": "<optional identifier for your interface, for example 'claude.ai' or 'chatgpt'>"
}
```

Only `page_path` and `text` are required. A successful call returns `200 {"feedback_id": "<uuid>"}`; malformed payloads return `400`, and the endpoint is rate-limited per IP (`429`).
