> ## Documentation Index
> Fetch the complete documentation index at: https://www.truefoundry.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Personal Access Tokens

> SDK methods to create, list, and revoke personal access tokens for TrueFoundry users.

## Methods

<Accordion title="list">
  List Personal Access Tokens created by the user in the current tenant.

  #### Parameters

  <ParamField body="limit" type="typing.Optional[int]">
    Number of items per page
  </ParamField>

  <ParamField body="offset" type="typing.Optional[int]">
    Number of items to skip
  </ParamField>

  <ParamField body="name_search_query" type="typing.Optional[str]">
    Return personal access tokens with names that contain this string
  </ParamField>

  #### Returns

  <ResponseField name="SyncPager[VirtualAccount, ListPersonalAccessTokenResponse]" type="SyncPager[VirtualAccount, ListPersonalAccessTokenResponse]">
    [🔗 ListPersonalAccessTokenResponse](/docs/truefoundry_sdk/types#listpersonalaccesstokenresponse)

    Returns all Personal Access Tokens created by the user in the current tenant.
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.personal_access_tokens.list(
      limit=10,
      offset=10,
      name_search_query="value",
  )

  # Iterate through results
  for item in response:
      print(item.name)

  # Or paginate page by page
  for page in response.iter_pages():
      for item in page:
          print(item.name)
  ```
</Accordion>

<Accordion title="create">
  Create Personal Access Token

  #### Parameters

  <ParamField body="name" type="str" required>
    serviceaccount name
  </ParamField>

  <ParamField body="expiration_date" type="typing.Optional[str]">
    Expiration date in ISO format (e.g. 2025-08-01T12:00)
  </ParamField>

  <ParamField body="account_name" type="typing.Optional[str]">
    Account name that owns this PAT
  </ParamField>

  #### Returns

  <ResponseField name="CreatePersonalAccessTokenResponse" type="CreatePersonalAccessTokenResponse">
    [🔗 CreatePersonalAccessTokenResponse](/docs/truefoundry_sdk/types#createpersonalaccesstokenresponse)

    Personal Access Token created successfully and returned
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.personal_access_tokens.create(
      name="value",
      expiration_date="value",
      account_name="value",
  )
  ```
</Accordion>

<Accordion title="revoke_all">
  Revoke All Personal Access Tokens for the user with the given email

  #### Parameters

  <ParamField body="email" type="str" required>
    Email of the user to revoke all Personal Access Tokens for
  </ParamField>

  #### Returns

  <ResponseField name="RevokeAllPersonalAccessTokenResponse" type="RevokeAllPersonalAccessTokenResponse">
    [🔗 RevokeAllPersonalAccessTokenResponse](/docs/truefoundry_sdk/types#revokeallpersonalaccesstokenresponse)

    All Personal Access Tokens revoked successfully
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.personal_access_tokens.revoke_all(
      email="value",
  )
  ```
</Accordion>

<Accordion title="delete">
  Delete Personal Access Token associated with the provided serviceAccountId

  #### Parameters

  <ParamField body="id" type="str" required>
    serviceaccount id
  </ParamField>

  #### Returns

  <ResponseField name="DeletePersonalAccessTokenResponse" type="DeletePersonalAccessTokenResponse">
    [🔗 DeletePersonalAccessTokenResponse](/docs/truefoundry_sdk/types#deletepersonalaccesstokenresponse)

    Personal Access Token deleted successfully
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.personal_access_tokens.delete(
      id="id_value",
  )
  ```
</Accordion>

<Accordion title="get">
  Get an existing Personal Access Token by name, if it doesn't exist, it will create a new one and return the PAT data along with a fresh token.

  #### Parameters

  <ParamField body="name" type="str" required />

  #### Returns

  <ResponseField name="GetOrCreatePersonalAccessTokenResponse" type="GetOrCreatePersonalAccessTokenResponse">
    [🔗 GetOrCreatePersonalAccessTokenResponse](/docs/truefoundry_sdk/types#getorcreatepersonalaccesstokenresponse)

    Personal Access Token found successfully and returned with token
  </ResponseField>

  #### Usage

  ```python lines theme={"dark"}
  from truefoundry import TrueFoundry

  client = TrueFoundry(
      api_key="YOUR_API_KEY",
      base_url="https://yourhost.com/path/to/api",
  )

  client.personal_access_tokens.get(
      name="value",
  )
  ```
</Accordion>
