# Set up environments and API keys

Create an environment such as Staging and an API key that sends to it, so test runs stay out of production. Then put the key where each service runs.

An environment keeps one stage of your agents, such as staging or production, apart from the rest. Each environment has its own agents, data, API keys and rule modes. The API key a service sends with decides which environment its runs land in.

## How environments work [#how-environments-work]

The environment you are in shows at the top of every page, beside the workspace name. Its menu switches to another one. A new workspace on the Team or Enterprise plan starts with **Production** and **Development**. On Free it has only Production.

Rules and dashboards are shared by every environment. Each environment sets its own mode for a rule, which [How rules work](/rules) covers.

An environment with **Production environment** turned on keeps its data for as long as your [plan](/workspace/billing) keeps history. Any other environment keeps it for 30 days at most. You can shorten both under **Settings**, **Environments**.

## Create an environment [#create-an-environment]

You need the admin role and the Team or Enterprise [plan](/workspace/billing). On Free, **Environments** shows the one environment and a link to Billing.

1. Open **Settings**, then **Environments**, and select **Create environment**.
2. Enter a **Name**, such as `Staging`.
3. Leave **Production environment** off for test traffic. The switch keeps data longer and makes an upload ask you to confirm first.
4. Select **Create environment**.

## Create an API key [#create-an-api-key]

A key sends to the environment it was created in, and nothing in a trace can change that. You need the admin role.

1. Switch to the environment the key should send data to.
2. Open **Settings**, then **API keys**, and select **Create key**.
3. Enter a **Name** for the service that will use the key, such as `payments-agent staging`.
4. Select **Create key**, then **Copy key**. Amiril shows the key only this once. Select **Done**.

The framework guides create the same key from the **Data** page instead. There, **Set up a new installation** opens a setup panel with the same form under **Create a new key**. It also shows the key only once, with the endpoints beside it.

## Put the key where the service runs [#put-the-key-where-the-service-runs]

Use one key per service and environment. The same agent running in staging and in production gets two keys, one from each environment.

For OpenTelemetry, the key goes in the `OTEL_EXPORTER_OTLP_TRACES_HEADERS` variable as `Authorization=Bearer <your API key>`. [Send traces from any OpenTelemetry SDK](/traces/opentelemetry) has the full set of variables.

The [Amiril SDK](/sdk) takes the same kind of key. Set the key, the endpoint and a name for the service. Copy the **SDK endpoint** from the setup panel on the **Data** page, which shows it under **Endpoints** for any key:

```bash
export AMIRIL_API_KEY="<your API key>"
export AMIRIL_ENDPOINT="<the SDK endpoint>"
export AMIRIL_SERVICE="payments"
```

The SDK then reads your rules and reports what each rule decided. The service name keeps services that share a host apart on the **Installations** page.

A key only sends data and reads rules. To let an AI assistant such as Claude Code read your traces, connect it to the [Amiril MCP server](/assistants), where it signs in as you.

## Replace a key [#replace-a-key]

Create the new key first and deploy it. Then open the old key's menu on the **API keys** page, select **Revoke key** and confirm. Anything still using it stops working within about 10 seconds.

## Next steps

- [Send traces from any OpenTelemetry SDK](https://docs.amiril.ai/traces/opentelemetry.md): Point an OpenTelemetry exporter at Amiril with three standard variables, learn the span attributes Amiril reads and check that your traces arrived.
- [Upload a Langfuse export](https://docs.amiril.ai/traces/langfuse-export.md): Export your observations from Langfuse as a JSONL file and upload it on the Data page. Each trace in the file becomes a run of the agent it names.
- [Check your agent's tool calls with the Amiril SDK](https://docs.amiril.ai/sdk.md): The Amiril SDK runs inside your agent and checks each tool call against your rules before the tool runs. Pick the guide for your framework and language.

## More detail

- [Limits and defaults](https://docs.amiril.ai/assistant/limits.md): Every limit and default a customer can hit in Amiril, with its number: plan amounts, ingest sizes and rates, imports, rules, backtests, API and MCP rates, page sizes, retention, name lengths.
- [Permissions and roles](https://docs.amiril.ai/assistant/permissions.md): Every permission a change in Amiril can require, and which of the built-in roles, admin and member, has it.
- [Troubleshooting](https://docs.amiril.ai/assistant/troubleshooting.md): Symptom, cause, how to confirm and fix for common Amiril problems: missing runs, plan limits, wrong agent or environment, rules that never fire or never block, SDK, key, import and MCP failures.
