---
sidebar:
  label: roboto.config
  order: 7
title: roboto.config
---
## Module Contents

### DEFAULT_ROBOTO_CONFIG_DIR

```python
roboto.config.DEFAULT_ROBOTO_CONFIG_DIR
```

`from roboto.config import DEFAULT_ROBOTO_CONFIG_DIR`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/config.py#L28-L28)

Path of the Roboto config file when `ROBOTO_CONFIG_FILE` is unset: `~/.roboto/config.json`.

### DEFAULT_ROBOTO_DIR

```python
roboto.config.DEFAULT_ROBOTO_DIR
```

`from roboto.config import DEFAULT_ROBOTO_DIR`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/config.py#L25-L25)

Directory where the Roboto CLI, SDK and upload agent keep their files: `~/.roboto` in the user's home directory.

### DEFAULT_ROBOTO_PROFILE_NAME

```python
roboto.config.DEFAULT_ROBOTO_PROFILE_NAME = 'default'
```

`from roboto.config import DEFAULT_ROBOTO_PROFILE_NAME`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/config.py#L31-L31)

Name of the config file profile used when neither the caller, `ROBOTO_PROFILE`, nor the file names another.

### ROBOTO_API_ENDPOINT

```python
roboto.config.ROBOTO_API_ENDPOINT = 'https://api.roboto.ai'
```

`from roboto.config import ROBOTO_API_ENDPOINT`

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

URL of the Roboto API, used when neither `ROBOTO_SERVICE_ENDPOINT` nor a config file profile gives an endpoint.

### RobotoConfig

```python
class roboto.config.RobotoConfig(/, **data: Any)
```

`from roboto import RobotoConfig`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/config.py#L114-L258)

Bases: `pydantic.BaseModel`

Settings for making requests to Roboto: an access token, the API endpoint, an HTTP timeout and a cache directory.

Each profile in the Roboto config file holds these fields. `from_env` builds a config from the environment or from one of those profiles, and [`from_config()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_config) builds a client from it.

**Parameters**

- **data** (`Any`)

**Attributes**

- **RobotoConfig.api_key** (`str`): Access token to authenticate requests with, such as a personal access token beginning with `robo_pat_`.

- **RobotoConfig.cache_dir** (`pathlib.Path | None`) = `None`: Cache directory the `roboto cache` commands report on and clear.

  `None` uses the directory `resolve_cache_dir` returns.

- **RobotoConfig.default_http_timeout** (`roboto.env.Timeout`): Seconds to wait for each HTTP request to Roboto before giving up.

  `None` waits indefinitely, and `NotSet` uses the client's default of 30 seconds.

- **RobotoConfig.endpoint** (`str`) = `'https://api.roboto.ai'`: URL of the Roboto API to send requests to.

- **RobotoConfig.org_id** (`str | None`) = `None`: Organization to act in when the caller names none and `ROBOTO_ORG_ID` is unset.

  The CLI and [`from_env()`](/docs/reference/python-sdk/roboto/roboto_search#roboto.roboto_search.RobotoSearch.from_env) read it. Only a member of several organizations needs it. `roboto setup` saves it to the config file profile; a config built from `ROBOTO_API_KEY` or `ROBOTO_BEARER_TOKEN` has none.

#### RobotoConfig.from_env()

```python
@classmethod
def from_env(
    profile_override: Optional[str] = None,
    env: Optional[roboto.env.RobotoEnv] = None,
) -> RobotoConfig
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/config.py#L148-L247)

Build a config from the access token in the environment, or else from a profile in the Roboto config file.

A token in `ROBOTO_API_KEY` or `ROBOTO_BEARER_TOKEN` takes precedence, and is sent to the endpoint in `ROBOTO_SERVICE_ENDPOINT`, or to `https://api.roboto.ai` when that is unset; the config file is then not read. Without a token, the config comes from a profile in the file at `ROBOTO_CONFIG_FILE`, or `~/.roboto/config.json` when that is unset. In both cases, `ROBOTO_CACHE_DIR` and `ROBOTO_DEFAULT_HTTP_TIMEOUT`, when set, supply `cache_dir` and `default_http_timeout` over any value in the profile.

**Parameters**

- **profile_override** (`Optional[str]`): Config file profile to read, ahead of `ROBOTO_PROFILE` and the file's default profile. Ignored when the environment holds a token.
- **env** (`Optional[roboto.env.RobotoEnv]`): Roboto environment variables to read. Defaults to the process's own, through [`default()`](/docs/reference/python-sdk/roboto/env#roboto.env.RobotoEnv.default).

**Raises**

- `FileNotFoundError`: No access token is set and the config file does not exist.
- `OSError`: The config file exists but cannot be read.
- `ValueError`: The config file is not a JSON object, holds no valid profile, or has no profile by the chosen name.

**Returns**

- `RobotoConfig`

**Usage**

Make requests to Roboto with the config file's `prod` profile:

```python
from roboto.http import RobotoClient
config = RobotoConfig.from_env(profile_override="prod")
roboto_client = RobotoClient.from_config(config)
```

#### RobotoConfig.get_cache_dir()

```python
def get_cache_dir() -> pathlib.Path
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/config.py#L249-L258)

Return the cache directory the `roboto cache` commands report on and clear.

When `cache_dir` is `None`, this sets it to the directory `resolve_cache_dir` returns, creating that directory when it is the operating system's per-user cache directory.

**Returns**

- `pathlib.Path`

### RobotoConfigFileProfileV0

```python
class roboto.config.RobotoConfigFileProfileV0(/, **data: Any)
```

`from roboto.config import RobotoConfigFileProfileV0`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/config.py#L261-L277)

Bases: `pydantic.BaseModel`

Profile in a Roboto config file of the earlier format, which maps each profile name directly to a profile.

`RobotoConfig.from_env` reads a file in this format when it is not a valid `RobotoConfigFileV1`. Such a file names no default profile, so the profile named `default` is used when neither the caller nor `ROBOTO_PROFILE` names one.

**Parameters**

- **data** (`Any`)

**Attributes**

- **RobotoConfigFileProfileV0.default_endpoint** (`str`) = `'https://api.roboto.ai'`: URL of the Roboto API to send requests to.
- **RobotoConfigFileProfileV0.token** (`str`): Access token to authenticate requests with.

#### RobotoConfigFileProfileV0.to_config()

```python
def to_config() -> RobotoConfig
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/config.py#L275-L277)

Return this profile as a `RobotoConfig`, with `token` as its `api_key`.

**Returns**

- `RobotoConfig`

### RobotoConfigFileV1

```python
class roboto.config.RobotoConfigFileV1(/, **data: Any)
```

`from roboto.config import RobotoConfigFileV1`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/config.py#L280-L312)

Bases: `pydantic.BaseModel`

Contents of a Roboto config file in the `v1` format, which lists its profiles under `profiles`.

`RobotoConfig.from_env` reads a file in this format, and `roboto auth login` and `roboto setup` write one. Building it raises `pydantic.ValidationError` when:

- `version` is not `"v1"`.
- `profiles` is empty.
- `profiles` has no profile by the name `default_profile` gives.

**Parameters**

- **data** (`Any`)

**Attributes**

- **RobotoConfigFileV1.default_profile** (`str | None`) = `'default'`: Name of the profile to use when neither the caller nor `ROBOTO_PROFILE` names one.

  `None` uses the profile named `default`.

- **RobotoConfigFileV1.profiles** (`dict[str, RobotoConfig]`): Profiles keyed by name, each holding the settings for one access token and endpoint.

- **RobotoConfigFileV1.version** (`Literal['v1']`): Format of the config file, always `"v1"`.

#### RobotoConfigFileV1.validate()

```python
def validate()
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/config.py#L304-L312)

Reject a config file with no profiles, or whose default profile is not among them.

### logger

```python
roboto.config.logger
```

`from roboto.config import logger`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/config.py#L18-L18)

### requested_profile_name()

```python
def roboto.config.requested_profile_name(
    profile_override: Optional[str],
    env: roboto.env.RobotoEnv,
) -> Optional[str]
```

`from roboto.config import requested_profile_name`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/config.py#L80-L98)

Return the config file profile named by the caller or by `ROBOTO_PROFILE`.

`RobotoConfig.from_env`, `roboto auth login` and `roboto setup` choose a profile through it, so most code never calls it.

**Parameters**

- **profile_override** (`Optional[str]`): Profile the caller names, ahead of `ROBOTO_PROFILE`. An empty value counts as none.
- **env** (`roboto.env.RobotoEnv`): Roboto environment variables, whose `ROBOTO_PROFILE` applies when `profile_override` names none.

**Returns**

- `Optional[str]`: The profile's name, or `None` when neither names one, which selects the config file's default profile. `ROBOTO_PROFILE` set to an empty value names the `default` profile.

### resolve_cache_dir()

```python
def roboto.config.resolve_cache_dir(
    env: roboto.env.RobotoEnv,
    ensure_exists: bool,
) -> pathlib.Path
```

`from roboto.config import resolve_cache_dir`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/config.py#L41-L59)

Return the directory under which the Roboto CLI and SDK cache data they download from Roboto.

`RobotoConfig.get_cache_dir` finds the cache directory through it when the config sets no `cache_dir`, so most code never calls it.

**Parameters**

- **env** (`roboto.env.RobotoEnv`): Roboto environment variables, whose `ROBOTO_CACHE_DIR` names the directory when set.
- **ensure_exists** (`bool`): Whether to create the operating system's per-user cache directory when this returns it. A directory named by `ROBOTO_CACHE_DIR` is never created.

**Returns**

- `pathlib.Path`: `ROBOTO_CACHE_DIR` when set, otherwise the operating system's per-user cache directory for `roboto`, such as `~/.cache/roboto` on Linux.

### resolve_config_file()

```python
def roboto.config.resolve_config_file(env: roboto.env.RobotoEnv) -> pathlib.Path
```

`from roboto.config import resolve_config_file`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/config.py#L62-L77)

Return the path of the Roboto config file, which may not exist.

`RobotoConfig.from_env` finds the file to read, and `roboto auth login` and `roboto setup` the file to write, through it, so most code never calls it.

**Parameters**

- **env** (`roboto.env.RobotoEnv`): Roboto environment variables, whose `ROBOTO_CONFIG_FILE` names the file when set.

**Returns**

- `pathlib.Path`: `ROBOTO_CONFIG_FILE` when set, otherwise `~/.roboto/config.json`.

### resolved_profile_name()

```python
def roboto.config.resolved_profile_name(
    requested: Optional[str],
    default_profile: Optional[str],
) -> str
```

`from roboto.config import resolved_profile_name`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/config.py#L101-L111)

Return the profile `requested` names, else the file's `default_profile`, else `default`.

`RobotoConfig.from_env` chooses the profile to read, and `roboto auth login` and `roboto setup` the profile to save a new token to, through it, so most code never calls it.

**Parameters**

- **requested** (`Optional[str]`): Profile the caller or `ROBOTO_PROFILE` names, from `requested_profile_name`.
- **default_profile** (`Optional[str]`): The config file's `default_profile`, or `None` when it names none.

**Returns**

- `str`
