---
sidebar:
  hidden: true
title: roboto.domain.tokens.operations
---
## Module Contents

### CreateCredentialRequest

```python
class roboto.domain.tokens.operations.CreateCredentialRequest(/, **data: Any)
```

`from roboto.domain.tokens import CreateCredentialRequest`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/tokens/operations.py#L47-L89)

Bases: `pydantic.BaseModel`

Request body for `POST /v1/tokens/requests`.

Sent by `roboto auth login`. The request asks a user to approve, in the browser, a personal access token for the CLI. The CLI then redeems the approval with `ExchangeCredentialRequestCode`. A field outside the limits its docstring gives raises `RobotoInvalidRequestException`. Building the model raises `pydantic.ValidationError` for a `code_challenge_method` other than `"S256"`.

**Parameters**

- **data** (`Any`)

**Attributes**

- **CreateCredentialRequest.client_hostname** (`str`): Hostname the client declares, shown on the approval page: 1 to 255 printable ASCII characters.

- **CreateCredentialRequest.client_version** (`str`): CLI version the client declares, shown on the approval page: 1 to 64 printable ASCII characters.

- **CreateCredentialRequest.code_challenge** (`str`): Unpadded base64url encoding of the SHA-256 digest of the CLI's secret verifier.

  The CLI sends the verifier itself when it redeems the approval, as `ExchangeCredentialRequestCode.code_verifier`.

- **CreateCredentialRequest.code_challenge_method** (`Literal['S256']`) = `'S256'`: Method that derives `code_challenge` from the verifier. Only `"S256"` is accepted.

- **CreateCredentialRequest.redirect_uri** (`str | None`) = `None`: Loopback URL the browser is sent to after approval, or `None` to have the user paste the authorization code.

  Must be `http://127.0.0.1:<port>/callback` or `http://[::1]:<port>/callback`, with a port from 1 to 65535 and no credentials, query string, or fragment. `None` makes the Roboto web app show the authorization code for the user to paste into the CLI, which is how sign-in works on a machine without a browser.

- **CreateCredentialRequest.state** (`str | None`) = `None`: Random value echoed back on the loopback redirect, so the CLI can reject callbacks it did not ask for.

  16 to 256 letters, digits, `-` or `_`. Required with `redirect_uri` and rejected without it.

- **CreateCredentialRequest.token_expiry_days** (`int`): Number of days the personal access token stays valid, counted from when the CLI redeems the approved request.

  From 1 to 365 (`MAX_CREDENTIAL_REQUEST_TOKEN_EXPIRY_DAYS`).

### CreateCredentialRequestResult

```python
class roboto.domain.tokens.operations.CreateCredentialRequestResult(/, **data: Any)
```

`from roboto.domain.tokens import CreateCredentialRequestResult`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/tokens/operations.py#L113-L126)

Bases: `pydantic.BaseModel`

Response body of `POST /v1/tokens/requests`: a credential request that expires ten minutes after creation.

**Parameters**

- **data** (`Any`)

**Attributes**

- **CreateCredentialRequestResult.approval_url** (`str`): URL in the Roboto web app where the user reviews and approves the request.
- **CreateCredentialRequestResult.confirmation_code** (`str`): Short code the CLI prints and the approval page shows, so the user can check they are the same request.
- **CreateCredentialRequestResult.credential_request_id** (`str`): Unique ID of the credential request. Redeeming it also requires its authorization code and secret verifier.
- **CreateCredentialRequestResult.expires** (`datetime.datetime`): Time after which the request can no longer be approved or redeemed.

### CreateTokenRequest

```python
class roboto.domain.tokens.operations.CreateTokenRequest(/, **data: Any)
```

`from roboto.domain.tokens import CreateTokenRequest`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/tokens/operations.py#L21-L44)

Bases: `pydantic.BaseModel`

Request body to create an access token.

Sent by [`create()`](/docs/reference/python-sdk/roboto/domain/tokens/token#roboto.domain.tokens.token.Token.create) and [`create_token()`](/docs/reference/python-sdk/roboto/domain/devices/device#roboto.domain.devices.device.Device.create_token).

**Parameters**

- **data** (`Any`)

**Attributes**

- **CreateTokenRequest.api_scopes** (`set[roboto.auth.scope.ApiScope] | None`) = `None`: API scopes the token is limited to. `None` or an empty set grants every scope.

  The token cannot be granted more than the credential creating it holds.

- **CreateTokenRequest.description** (`str | None`) = `None`: Human-readable description of the token.

- **CreateTokenRequest.expiry_days** (`int`) = `None`: Number of days the token stays valid, counted from its creation.

- **CreateTokenRequest.name** (`str`) = `None`: Human-readable name of the token.

### ExchangeCredentialRequestCode

```python
class roboto.domain.tokens.operations.ExchangeCredentialRequestCode(/, **data: Any)
```

`from roboto.domain.tokens import ExchangeCredentialRequestCode`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/tokens/operations.py#L92-L110)

Bases: `pydantic.BaseModel`

Request body for `POST /v1/tokens/requests/exchange`.

Sent by `roboto auth login`. Redeems an approved credential request's authorization code for a personal access token. `authorization_code` and `code_verifier` are left out of the model's `repr` and of a `pydantic.ValidationError`'s message, but `ValidationError.errors()` still includes them unless called with `include_input=False`.

**Parameters**

- **data** (`Any`)

**Attributes**

- **ExchangeCredentialRequestCode.authorization_code** (`str`) = `None`: One-time authorization code, delivered to the CLI by the loopback redirect or pasted by the user.
- **ExchangeCredentialRequestCode.code_verifier** (`str`) = `None`: Secret verifier whose SHA-256 digest, encoded as unpadded base64url, was sent as `code_challenge`.
- **ExchangeCredentialRequestCode.credential_request_id** (`str`): ID of the credential request the code was issued for.
- **ExchangeCredentialRequestCode.model_config**: Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

### MAX_CREDENTIAL_REQUEST_TOKEN_EXPIRY_DAYS

```python
roboto.domain.tokens.operations.MAX_CREDENTIAL_REQUEST_TOKEN_EXPIRY_DAYS = 365
```

`from roboto.domain.tokens import MAX_CREDENTIAL_REQUEST_TOKEN_EXPIRY_DAYS`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/tokens/operations.py#L14-L14)

Maximum lifetime of the token a `CreateCredentialRequest` asks for, in days.

It matches the longest lifetime the Roboto web app offers for a new personal access token.
