# Manage another account with your own API key: account context (API, CLI, MCP, Terraform)

https://www.gyrohosting.com/en/knowledgebase/article/baska-hesapta-api-cli

- **What you will learn**: When the owner of an account has added you on the **Sub-Accounts** page, you can manage that account through the API, the `gyro` CLI, MCP and Terraform, just as you do in the panel. This guide shows how, which permission allows what, and how access is removed.
- **Time**: 8 minutes

## 1. How it works

In the panel, when an account owner invites you on the **Sub-Accounts** page and grants permissions, you sign in with your own e-mail and password and switch to that account. The API works the same way:

- You **do not need** the owner's API key. Create a key in your own account.
- Add the `X-Account-Id: <account id>` header and the request runs in that account.
- You can do **exactly** what the panel allows your user there. This is checked on every request: when the owner removes or suspends your access, or turns a permission off, the next request is refused.
- Your key's own scopes still apply. A read-only key stays read-only in another account.
- Without the header nothing changes: requests run in your own account.

## 2. What the account owner does

1. In the client area, open **Sub-Accounts** and click **Invite User**.
2. Enter the e-mail address of your Gyro account and pick the permissions. The presets are Full Access, Billing, Support and Custom.
3. Change access at any time with **Edit Access**, **Suspend Access** or **Remove**. The change applies to the API immediately.

## 3. Panel permissions and their API equivalents

| Panel permission | What it allows in the API |
| --- | --- |
| View Services | Read servers, services, containers, storage and network resources (`GET /cloud/...`, `GET /services`) |
| Manage Services | Power actions, snapshots, SSH keys, delete, renew, and every service tool that changes something (also read tools that run an action, e.g. pipeline logs) |
| View & Change Passwords | Answers containing passwords and secrets; console, password reset, rescue mode, rebuild (also as a bulk action), OS reinstall, two-factor authentication, webmail, access keys, the pipeline webhook secret. Without it, secret fields in answers come back as `null` and these operations are refused |
| Sign In to Control Panels | One-click sign-in to a service control panel (`POST /services/{id}/sso`), webmail and groupware sign-in |
| Place New Orders | Orders, new servers, domain registration and transfer, plan changes and add-ons. `"confirm": true` and an `Idempotency-Key` are required; payment comes from that account's balance **only**, its saved card is never charged (`422 balance_only`) |
| View / Manage Domains | Domains, DNS, nameservers |
| View Invoices | Invoices and paying them |
| View & Open Tickets | Support tickets (a ticket you open is filed in that account) |
| Affiliate Account | Affiliate information (read only) |

**Account owner only** (`403 account_owner_only`): API keys, webhooks, managing Sub-Accounts, reseller customers, profile and addresses, balance, saved cards, balance top-up and the API activity log (`GET /cloud/activity`). Your permissions never open these.

## 4. With the API

List the accounts you can reach:

```
curl -s https://www.gyrohosting.com/api/v1/client/accounts \
  -H "Authorization: Bearer $GYRO_TOKEN"
```

Your own account comes first (`"role": "owner"`), then every account you are a member of. Each entry has `permissions` (the panel permissions) and `access` (a summary: `services` none/read/manage, `invoices`, `tickets`, `orders`, `passwords`). E-mail addresses are masked.

Run a request in that account:

```
curl -s https://www.gyrohosting.com/api/v1/client/cloud/servers \
  -H "Authorization: Bearer $GYRO_TOKEN" \
  -H "X-Account-Id: 12345"
```

Every answer in an account context carries an `X-Gyro-Account-Id` header. The account owner sees your changes in their own `GET /cloud/activity` log, marked with `acting_user_id`.

## 5. With the gyro CLI, MCP and Terraform

**gyro CLI** (1.44.0 or later):

```
gyro account list                       # accounts you can reach and your permissions
gyro server list --account 12345        # for one command
export GYRO_ACCOUNT=12345               # for this shell
gyro account use 12345                  # make it the profile default
gyro account use self                   # back to your own account
```

When you sign in with `gyro auth login` in the browser, you can pick the default account on the approval page. The choice is saved in the profile. `gyro auth status` shows which account you are working in.

**Gyro MCP** (0.16.0 or later): the `list_accounts` tool lists the accounts. Every account tool takes `account_id`, and `use_account` changes the session default. To set a default at start, use the `GYRO_ACCOUNT=12345` environment variable for the local server, or add an `X-Account-Id` header to the client configuration for the remote endpoint.

**Terraform** (provider 0.41.0 or later):

```
provider "gyro" {}                 # your own account

provider "gyro" {
  alias      = "gyro_proje"
  account_id = 12345               # the account that added you under Sub-Accounts
}

resource "gyro_ssh_key" "deploy" {
  provider   = gyro.gyro_proje
  name       = "gyro-proje-deploy"
  public_key = file("~/.ssh/id_ed25519.pub")
}
```

`account_id` is deliberately not read from an environment variable or the CLI profile. A state belongs to one account: if `account_id` changes, existing resources look deleted and Terraform plans to create them again.

## 6. Errors

| Code | Meaning | What to do |
| --- | --- | --- |
| `403 account_not_accessible` | You are not a user of this account, your access is suspended, the account is not active, or that account may not use the API | Check with `gyro account list`; ask the owner for access |
| `403 account_permission_denied` | Your permissions do not cover this operation; `details.missing` names the missing permission | The owner can grant it on the Sub-Accounts page |
| `403 account_owner_only` | Only the account owner can do this | Ask the account owner |
| `403 account_context_forbidden` | Sub-account and narrowed keys cannot switch accounts | Use a full key of your own account |
| `422 invalid_account_id` | The header value is not a valid account number | Use the `id` from `gyro account list` |
| `422 balance_only` | In another account, payment comes from that account's balance only (a card or another method was chosen) | Leave the payment method as balance; if the balance is short, the owner tops it up |
| `422 account_context_unsupported` | This endpoint only works in your own account (e.g. the prepaid balance statement) | Call it without the header |
| `422 idempotency_key_reuse` | The same `Idempotency-Key` was already used for another account | Use a new key for each account (the CLI and MCP do this for you) |

## 7. Frequently asked questions

**Do I need the account owner's API key or password?**

No. You work with your own key, and the owner never has to share a key with anyone.

**What happens to my key when my access is removed?**

It keeps working in your own account. Requests to the other account answer `403 account_not_accessible` at once.

**Who pays when I order in another account?**

The account you ordered in pays, from its balance only. The owner's saved card is never charged this way; the same applies to invoice payments and domain registration / transfer. This needs the "Place New Orders" permission ("View Invoices" for invoices). Every operation that spends money requires `"confirm": true` and an `Idempotency-Key`.

**Can I see passwords?**

Only with the "View & Change Passwords" permission. Without it, password and secret fields come back as `null`, and operations such as console access, password reset, rescue mode, rebuild and two-factor setup are refused.

**Can the account owner see what I did?**

Yes. In the owner's API log (`/cloud/activity`, open to the owner only), every change is shown with the user who made it as `acting_user_id`.

**Does this work with sub-account keys (reseller customers or narrowed keys)?**

No. The account context only works with the full keys of your own account.

## Next step

- Getting started with the API: [First steps with the Gyro API](https://www.gyrohosting.com/en/knowledgebase/article/gyro-api-ilk-adim)
- Command line: [Install the gyro CLI](https://www.gyrohosting.com/en/knowledgebase/article/gyro-cli-kurulum)
- AI assistants: [The Gyro MCP server](https://www.gyrohosting.com/en/knowledgebase/article/gyro-mcp-sunucusu)
- Infrastructure as code: [Terraform with Gyro Cloud servers](https://www.gyrohosting.com/en/knowledgebase/article/terraform-ile-gyro-bulut)
- Developer docs: [Working in another account (X-Account-Id)](https://www.gyrohosting.com/developers/en/guides/auth.html)
