# Baseten configuration

Cartography reads your Baseten organization through the read-only `GET` endpoints of the
[Baseten Management API](https://docs.baseten.co/reference/management-api/overview). It
needs one Baseten API key. The API is scoped to the key's organization, so you don't pass an
organization ID.

## Authentication

Baseten filters several Management API responses by the role of the key's owner, so use a
key that can see the whole organization:

- **Required:** a personal API key that belongs to an organization **Admin**. It's the
  only key type that can read the organization's members, every team, every team API key,
  and every member's personal API keys.
- A team API key with **Full access to all team models** reads only its own team's models,
  Chains, and secrets. Don't use one for an organization-wide inventory.
- An API key management key (`WORKSPACE_MANAGE_API_KEYS`) can only list teams, models, and
  API keys. Cartography can't sync the rest of the organization with it.

Baseten can return successful list responses with only the resources the key can see.
After each sync, Cartography removes Baseten nodes and relationships that the key no
longer returns, so keep organization Admin access when rotating the key. To sync with a
key that can't see the full organization, pass `--baseten-skip-cleanup`; Cartography then
loads the available inventory and keeps previously synced nodes and relationships.

Baseten requires personal API keys to expire within 90 days, or sooner if your organization
sets a shorter limit, and revokes personal keys that go unused for 30 days. Rotate the key
before it expires. A daily sync keeps it from being revoked for inactivity.

To create the key, sign in to [app.baseten.co](https://app.baseten.co) as an organization
Admin, open **Organization settings** > [**API keys**](https://app.baseten.co/settings/api_keys),
choose **Create API key**, and select **Personal**. Store the key in an environment variable.

## Required permissions

Cartography calls these endpoints:

| Endpoint | Ingests | Who can read it |
| --- | --- | --- |
| `GET /v1/organizations/me` | `BasetenOrganization` | Any API key. |
| `GET /v1/teams` | `BasetenTeam` | Teams the key's owner can access. Organization Admins see every team. |
| `GET /v1/users` | `BasetenUser` | Not documented. Use an organization Admin's key. |
| `GET /v1/models` | `BasetenModel` | Viewer role or higher in the model's team. |
| `GET /v1/teams/{team_id}/secrets` | `BasetenSecret` (metadata only) | Viewer role or higher in the team. |
| `GET /v1/api_keys` | `BasetenApiKey` (metadata only) | Organization Admins see every key. Team Admins see their teams' keys. Other users see their own keys. |
| `GET /v1/teams/{team_id}/environment_groups` | `BasetenEnvironmentGroup` | Not documented. Use an organization Admin's key. |

Cartography fetches every endpoint, including all pages and per-team
responses, before writing to Neo4j. If an API request fails, for example with
`403 Forbidden` or a timeout, the Baseten sync stops and leaves the previous sync's
nodes and relationships unchanged. Once loading starts, database writes and cleanup
commit in separate transactions; a database failure can leave partial updates.

`BasetenApiKey.id` combines the organization ID and key prefix as
`<organization_id>/<prefix>`. Use `BasetenApiKey.prefix` to query the original
Baseten prefix.

## Configure Cartography

| Option | Description |
| --- | --- |
| `--baseten-api-key-env-var` | Name of the environment variable that holds the Baseten API key. |
| `--baseten-skip-cleanup` | Keep stale nodes and relationships instead of removing them after the sync. Use when the API key can't see the full organization. |

## Run Cartography

```bash
export BASETEN_API_KEY='<api-key>'
cartography \
  --selected-modules baseten \
  --baseten-api-key-env-var BASETEN_API_KEY
```

## References

- [Baseten API keys](https://docs.baseten.co/organization/api-keys)
- [Baseten access control](https://docs.baseten.co/organization/access) and
  [teams](https://docs.baseten.co/organization/teams)
- [Management API OpenAPI specification](https://api.baseten.co/v1/spec)
