Create an access token
const url = 'https://gitea.example.com/api/v1/users/example/tokens';const options = { method: 'POST', headers: {Authorization: 'Basic <credentials>', 'Content-Type': 'application/json'}, body: '{"description":"example","expires_in_days":1,"justification":"example","kind":"example","name":"example","owner":"example","repo_selection":"example","repositories":["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 '{ "description": "example", "expires_in_days": 1, "justification": "example", "kind": "example", "name": "example", "owner": "example", "repo_selection": "example", "repositories": [ "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 of the user whose token is to be created
Request Body
Section titled “Request Body”CreateAccessTokenOption options when create access token
object
The description of the token
The lifetime in days, 0 means no expiry. Fine-grained tokens default to 30 days (1-366), classic tokens to no expiry
Why the token is needed, shown to the approvers of the organization that owns a fine-grained token
The kind of token to create: classic (default) or fine_grained
The user or organization a fine-grained token is limited to, defaults to the token holder
The repository selection of a fine-grained token: public, all or selected
The repositories of a fine-grained token with repo_selection selected, as owner/name
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.
object
The timestamp when the token was created
The description of the token
Whether the token is disabled
The timestamp when the token stops working, absent if it never does
The unique identifier of the access token
The kind of the token: classic or fine_grained
The timestamp when the token was last used
The name of the access token
The user or organization a fine-grained token is limited to
The repository selection of a fine-grained token: public, all or selected
The selected repositories of a fine-grained token, as owner/name
The scopes granted to this access token
The SHA1 hash of the access token
The last eight characters of the token
Examplegenerated
{ "created_at": "2026-04-15T12:00:00Z", "description": "example", "disabled": true, "expires_at": "2026-04-15T12:00:00Z", "id": 1, "kind": "example", "last_used_at": "2026-04-15T12:00:00Z", "name": "example", "owner": "example", "repo_selection": "example", "repositories": [ "example" ], "scopes": [ "example" ], "sha1": "example", "token_last_eight": "example"}APIError is error format response
Headers
Section titled “Headers”APIForbiddenError is a forbidden error response