---
title: "Give your team Claude Code and Codex without sharing provider keys"
description: "Hand out per-developer and service account gateway keys instead of OpenAI or Anthropic API keys. Revoke one person, rotate provider keys, and attribute every call."
tags: [guide, agents]
---

# Give your team Claude Code and Codex without sharing provider keys

The fastest way to roll out a coding agent is to paste one OpenAI or Anthropic API key into a team wiki. It is also the hardest setup to undo: you can't revoke one person, you can't tell who spent what, and rotating the key breaks everyone at once. An AI gateway fixes this by giving every developer and every service its own key, while the provider key stays in one place.

**Start with Langfuse** [Sign up](/cloud)

**TL;DR:** With the [Langfuse AI Gateway](/docs/gateway/overview), admins store provider connections once, and clients get gateway keys. **User keys** belong to one developer, record that developer on every call, and stop working when they leave the organization. **Service account keys** belong to the organization, for CI and shared services. Keys can expire, are revoked immediately, can carry team or cost-center metadata, and can't read any other Langfuse data. Creating and revoking keys is recorded in the audit log.

  ![Create gateway key dialog with the Issued as choice, name, expiration, and metadata fields](/images/docs/ai-gateway/create-key.png)

## Three kinds of keys [#key-types]

The gateway separates the key that reaches the provider from the keys clients hold:

| Key                 | Held by               | Purpose                                                        |
| ------------------- | --------------------- | -------------------------------------------------------------- |
| Provider connection | Only the gateway      | Calls your model provider on your account                      |
| User key            | One developer         | Coding agents and local development                            |
| Service account key | A CI job or a service | Pipelines and shared services that must outlive any one person |

Because clients never see the provider connection's API key, you can rotate it without touching any client, and revoke one person's access without affecting anyone else. The provider still bills model usage to your provider account. See [keys and connections](/docs/gateway/concepts#credential-types).

## Per-developer keys for coding agents [#user-keys]

Every gateway user creates their own key under **AI Gateway → Gateway keys** and pastes it into their agent's configuration. For Claude Code, that is `ANTHROPIC_AUTH_TOKEN` next to the gateway base URL. For Codex, it is the `env_key` of a custom provider. The [coding agent guides](/integrations#developer-tools) show the exact setup for each agent.

What makes user keys suitable for a team rollout:

- **Every call is attributed.** A user key always records its owner's email as the trace user, and clients can't override it.
- **Access ends with membership.** A user key stops working when its owner leaves the organization, changes to a role that can't call the gateway, or deletes their account. No cleanup is needed.
- **People don't need project access.** The **AI Gateway** organization role lets someone call the gateway, manage their own keys, and see their own usage, without seeing any Langfuse project. See [roles and permissions](/docs/administration/rbac).

  Viewers can't create gateway keys. Give developers the AI Gateway, Member,
  Admin, or Owner role.

## Service account keys for CI and shared services [#service-accounts]

Owners and admins can issue a key as **Service account** instead of **My user**. A service account key:

- keeps working when people join or leave, because it belongs to the organization;
- uses its own name as the trace user, so name it after what uses it, such as `CI release pipeline`;
- accepts a `langfuse-user-id` [header](/docs/gateway/features/tracing#headers), so a shared service can forward the end user it is acting for.

Use one service account key per pipeline or service. That keeps cost per service visible and lets you revoke one without touching the others.

## Expiry, revocation, and audit [#lifecycle]

- **Expiry** is optional on any key, and useful for contractors and temporary projects.
- **Revocation** takes effect immediately.
- **Audit logs** record creating and revoking keys, so security reviews can answer who had access and when. See [audit logs](/docs/administration/audit-logs).
- **Scope** is limited to the gateway: a gateway key can't read or write traces, prompts, or any other Langfuse data.

## Attribute keys to teams and cost centers [#metadata]

When you create a key, add metadata such as `team: platform` or `cost_center: 4711`. The gateway attaches it to every generation recorded with that key, under `langfuse.gateway.api_key.metadata.<key>`, and request headers can't override it. Filter traces and [custom dashboards](/docs/metrics/features/custom-dashboards) on it to see cost per team.

To change metadata later, select **Edit key** in **AI Gateway → Gateway keys**. Whoever manages a key can edit it, so developers set the metadata on their own user keys. For cost centers that must be admin-approved, use service account keys, which only admins and owners create, or review the metadata on user keys. For a full cost-attribution setup, see [FinOps for AI](/resources/engineering/finops-for-ai).

## Limit which models keys can call [#models]

By default, a key can call every model enabled on your provider connections. To keep expensive or unapproved models out for everyone, turn them off per connection. To narrow one key, add model patterns such as `openai-prod:*` when you create it or with **Edit key**. See [restrict models per API key](/docs/gateway/features/models#restrict-models-per-key) and [control which models your company can use](/resources/engineering/ai-model-allowlist).

## A rollout checklist [#checklist]

1. Add provider connections and choose the [ingestion mode](/docs/gateway/features/tracing#ingestion-modes) in **AI Gateway → Overview**.
2. Turn off models you don't want used, and plan which keys get model patterns.
3. Invite developers with the AI Gateway role, and ask each to create their own key.
4. Issue one service account key per CI pipeline and shared service, with team metadata.
5. Remove any shared provider keys from wikis, `.env` files, and CI secrets, and rotate the provider key once everyone has moved.

## FAQ

### What happens to a developer's gateway key when they leave? [#what-happens-when-someone-leaves]

It stops working as soon as they lose gateway access, for example when they are removed from the organization. Service account keys are not affected by membership changes, so shared services keep running.

### How do I rotate the OpenAI or Anthropic key? [#can-i-rotate-provider-keys]

Update the provider connection in **AI Gateway → Connections & Models → Connections**. Clients hold gateway keys, not the provider key, so no client configuration changes.

### Can a gateway key read my Langfuse traces? [#does-a-gateway-key-expose-my-langfuse-data]

No. A gateway key can only call the gateway. Reading traces requires Langfuse project API keys or a role with project access.

[Ask another question](/docs/ask-ai)

**Start with Langfuse** [Sign up](/cloud)

<!-- agent-instructions -->

---

## Agent Instructions

This page is part of the [Langfuse](https://langfuse.com) documentation, published as plain Markdown for AI agents. Every page is available as Markdown by appending `.md` to its URL, or by sending an `Accept: text/markdown` header. This page: `https://langfuse.com/resources/engineering/ai-gateway-api-keys.md`.

### Querying these docs

If the answer is not on this page, query the documentation instead of guessing:

- **Semantic search** across all Langfuse docs, returning an answer with the relevant pages and excerpts. Ask a specific, self-contained question:

  ```bash
  curl -sG "https://langfuse.com/api/search-docs" --data-urlencode "query=How do I trace a LangGraph agent?"
  ```

- **Index of every page**: <https://langfuse.com/llms.txt>, with per-section indexes [llms-docs.txt](https://langfuse.com/llms-docs.txt), [llms-integrations.txt](https://langfuse.com/llms-integrations.txt), and [llms-self-hosting.txt](https://langfuse.com/llms-self-hosting.txt).

### Before writing Langfuse code

- **Install the [Langfuse Agent Skill](https://langfuse.com/docs/api-and-data-platform/features/agent-skill).** It encodes Langfuse's own best practices for instrumentation, prompt management, and evaluation, and materially improves results.
- **Read [What does a good trace look like?](https://langfuse.com/docs/observability/best-practices.md)** before instrumenting an application.
- **Verify endpoints, parameters, and response fields** against the [API reference](https://api.reference.langfuse.com) instead of inferring them from code examples.
- **Use the [Langfuse CLI](https://langfuse.com/docs/api-and-data-platform/features/cli)** (`npx @langfuse/cli api <resource> <action>`) to read or write traces, prompts, datasets, and scores from the terminal.

Found an error in these docs? Please open an issue at <https://github.com/langfuse/langfuse-docs/issues>.
