# Access platform APIs from within a module

To use the platform or machine APIs, you must authenticate using API keys.

- [Use platform APIs from a module](https://docs.viam.com/build-modules/platform-apis/#use-platform-apis-from-a-module)
- [Use the machine management API from a module](https://docs.viam.com/build-modules/platform-apis/#use-the-machine-management-api-from-a-module)

## Use platform APIs from a module

The following steps show you how to use the following APIs from a module:

- [Fleet management (`app_client`)](https://docs.viam.com/reference/apis/fleet/)
- [Data client (`data_client`)](https://docs.viam.com/reference/apis/data-client/)
- [ML training (`ml_training_client`)](https://docs.viam.com/reference/apis/ml-training-client/)
- [Billing (`billing_client`)](https://docs.viam.com/reference/apis/billing-client/)

- [Python](https://docs.viam.com/build-modules/platform-apis/#tabset-build-modulesplatform-apis-1-0)
- [Go](https://docs.viam.com/build-modules/platform-apis/#tabset-build-modulesplatform-apis-1-1)

1. Add the following imports:

```python

```

2. Add the `viam_client` and other clients to the resource class:

```python

```

3. Initialize the clients and use them:

```python

```

1. Add the following imports:

```go

```

2. Add the `viam_client` and other clients to the resource class:

```go

```

3. Initialize the clients and use them:

```go

```

### Elevate access

The [module environment variables](https://docs.viam.com/reference/) `VIAM_API_KEY` and `VIAM_API_KEY_ID` provide [machine owner access](https://docs.viam.com/organization/rbac/) for the machine the module is running on.

If you need a higher level of access, you can pass API keys as part of the module configuration:

1. Create an API key with the appropriate [permissions](https://docs.viam.com/organization/rbac/) from your organization settings page.

2. Add the API key and API key ID values to the module configuration:

```json
   {
        "modules": [\
          {\
            "type": "registry",\
            "name": "example-module",\
            "module_id": "naomi:example-module",\
            "version": "latest",\
            "env": {\
              "VIAM_API_KEY": "abcdefg987654321abcdefghi",\
              "VIAM_API_KEY_ID": "1234abcd-123a-987b-1234567890abc"\
            }\
          }\
        ]
   }
   ```

This changes the environment variables `VIAM_API_KEY` and `VIAM_API_KEY_ID` from the default to the provided ones.

## Use the machine management API from a module

To use the [machine management (`robot_client`) API](https://docs.viam.com/reference/apis/robot/), you must get the machine’s FQDN and API keys from the module environment variables.

- [Python](https://docs.viam.com/build-modules/platform-apis/#tabset-build-modulesplatform-apis-2-0)
- [Go](https://docs.viam.com/build-modules/platform-apis/#tabset-build-modulesplatform-apis-2-1)

1. Add the following imports and the `create_robot_client_from_module` method:

```python

```

2. Add the `robot_client` or other clients to the resource class:

```python

```

3. Initialize the client and use it:

```python

```

1. Add the following imports and the `createRobotClientFromModule` function:

```go

```

2. Add the `viam_client` and other clients to the resource class:

```go

```

3. Initialize the clients and use them:

```go

```

To elevate access for the machine management API, follow the same steps described in [Elevate access](https://docs.viam.com/build-modules/platform-apis/#elevate-access) above.
