Create an access token
POST
/users/{username}/tokens
const url = 'https://gitea.example.com/api/v1/users/example/tokens';const options = { method: 'POST', headers: {Authorization: 'Basic <credentials>', 'Content-Type': 'application/json'}, body: '{"name":"example","scopes":["all","read:activitypub","read:issue","write:misc","read:notification","read:organization","read:package","read:repository","read:user"]}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://gitea.example.com/api/v1/users/example/tokens \ --header 'Authorization: Basic <credentials>' \ --header 'Content-Type: application/json' \ --data '{ "name": "example", "scopes": [ "all", "read:activitypub", "read:issue", "write:misc", "read:notification", "read:organization", "read:package", "read:repository", "read:user" ] }'Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”username
required
string
Username of the user whose token is to be created
Request Body
Section titled “Request Body”Media typeapplication/json
CreateAccessTokenOption options when create access token
object
name
required
string
scopes
Array<string>
Example
[ "all", "read:activitypub", "read:issue", "write:misc", "read:notification", "read:organization", "read:package", "read:repository", "read:user"]Responses
Section titled “Responses”AccessToken represents an API access token.
Media typeapplication/json
AccessToken represents an API access token.
object
created_at
The timestamp when the token was created
string format: date-time
id
The unique identifier of the access token
integer format: int64
last_used_at
The timestamp when the token was last used
string format: date-time
name
The name of the access token
string
scopes
The scopes granted to this access token
Array<string>
sha1
The SHA1 hash of the access token
string
token_last_eight
The last eight characters of the token
string
Examplegenerated
{ "created_at": "2026-04-15T12:00:00Z", "id": 1, "last_used_at": "2026-04-15T12:00:00Z", "name": "example", "scopes": [ "example" ], "sha1": "example", "token_last_eight": "example"}APIError is error format response
Media typeapplication/json
Headers
Section titled “Headers”message
string
url
string
APIForbiddenError is a forbidden error response
Media typeapplication/json
Headers
Section titled “Headers”message
string
url
string