Skip to content

Security and governanceGuide

Short-lived credentials for AI APIs: replacing static keys

Every major AI provider now lets a workload authenticate with an identity it already has instead of a long-lived key in an environment variable. Here is what AWS, Google, Microsoft, OpenAI and Anthropic each offer, the migration traps, and how to bound the static keys that remain.

By INFRO Editorial

Published

9 min read

A glowing amber waveform crossing a dark ground above a row of small dots of light

In short

You can replace most static AI API keys with short-lived credentials: IAM roles and short-term Bedrock API keys on AWS, service accounts and Workload Identity Federation on Google Cloud, Entra ID and managed identities for Azure OpenAI with key access disabled, and Workload Identity Federation on both OpenAI and Anthropic, which exchange your identity provider's token for one that expires in an hour or less. Where a static key is unavoidable, give it an expiry, the narrowest scope, a rotation with overlap and a spend limit at the provider.

Key takeaways

  • AWS, Google Cloud and Azure all let workloads call their AI services with identity: IAM roles, service accounts with Workload Identity Federation, and Entra ID managed identities.
  • OpenAI and Anthropic now both offer Workload Identity Federation: a workload exchanges its identity provider's token for a provider token that lasts an hour or less.
  • Azure lets you disable key-based access entirely with disableLocalAuth, but the change can take up to several hours to reach the gateway that enforces it.
  • On Anthropic's SDKs a leftover ANTHROPIC_API_KEY silently wins over federation; unset it before you delete the key.
  • Static keys you cannot avoid need an expiry, the narrowest project or workspace scope, rotation with an overlap window and a provider-side spend limit.

How do you use short-lived credentials with AI APIs? Let the workload prove who it is with an identity it already has, and exchange that for a provider token that expires in minutes or hours. On AWS that is an IAM role (or a short-term Bedrock API key derived from one); on Google Cloud a service account, with Workload Identity Federation for workloads outside Google; on Azure an Entra ID managed identity, with key access disabled on the resource. OpenAI and Anthropic now both offer Workload Identity Federation, which trades a token from AWS, Google Cloud, Azure, Kubernetes, GitHub Actions or another OIDC issuer for a short-lived API token. Where a static key remains, give it an expiry, a narrow scope, a rotation with overlap and a provider-side spend limit.

The reason is simple: a static key works for anyone who copies it, from anywhere, until someone notices. A token that expires in an hour limits a leak to that hour, and one derived from workload identity cannot be pasted into a .env file in the first place.

What each provider offers

ProviderIdentity-based accessShort-lived tokenStatic key controls
AWS BedrockIAM roles for workloads1Short-term Bedrock API key, up to 12 hours2Long-term key with a set expiry; IAM can cap it at 90 days2
Google Vertex AIService accounts; Workload Identity Federation for outside workloads3Federated access tokens3Service account keys (Google calls them a security risk)3
Gemini APIAuth keys bound to a service account4—API restrictions; unrestricted keys rejected4
Azure OpenAIEntra ID, managed identities, RBAC roles5Entra access tokens5Key access can be disabled6
OpenAIWorkload Identity Federation7Exchanged access token7Expiry dates, maximum lifetime, creation controls8
AnthropicWorkload Identity Federation960–86,400 s access token9Workspace keys; rotate on a schedule10

AWS Bedrock: roles first, short-term keys second

AWS's IAM best practices say to "require workloads to use temporary credentials with IAM roles to access AWS"; on EC2, Lambda and other AWS compute, SDKs pick up role credentials automatically, and workloads elsewhere can obtain them through IAM Roles Anywhere, AssumeRoleWithWebIdentity with a JWT from your identity provider, or AssumeRoleWithSAML1. A Bedrock call signed with role credentials needs no API key at all.

For tools that only take a bearer token, Bedrock API keys come in two kinds. A short-term key lasts up to 12 hours or the session, whichever is shorter, inherits the permissions of the IAM principal that generated it, and is AWS's recommendation for production; a long-term key creates an IAM user and is "for exploration only"2. AWS's token generators return a cached short-term key and refresh it, so long-running applications call them before each request2.

IAM controls both kinds. bedrock:CallWithBearerToken with the bedrock:bearerTokenType condition (SHORT_TERM or LONG_TERM) allows or denies API key use per identity, and iam:ServiceSpecificCredentialAgeDays caps a long-term key's lifetime, for example at 90 days2. A compromised short-term key is invalidated by invalidating the session that generated it or by denying CallWithBearerToken2. One audit detail: API calls are logged in CloudTrail, the keys themselves are not2.

Google Cloud: service accounts and federation

On Google Cloud, Vertex AI calls from Google compute use the attached service account. Workloads elsewhere use Workload Identity Federation, which Google positions as the replacement for service account keys: those keys "are powerful credentials, and can present a security risk if they are not managed correctly", and federation "eliminates the maintenance and security burden" of them3. It accepts AWS, Microsoft Entra ID, GitHub, GitLab, Kubernetes, Okta and any OIDC or SAML 2.0 identity provider, and returns short-lived access tokens; Google recommends granting the external identity direct resource access where the API supports it, with service account impersonation as the alternative3.

The Gemini API on Google AI Studio has moved the same way. Since 2026-05-28, new keys created in AI Studio are auth keys bound to a service account, so requests run under that account's identity and are restricted to the Gemini API by default; the API rejects unrestricted standard keys4. They are still keys a person can copy, so treat them as static credentials with the controls below.

Azure OpenAI: Entra ID, then turn keys off

Microsoft's keyless guide makes the case directly: "Anyone who gains access to the key is able to authenticate to the service", while keyless authentication leaves no key or connection string to store5. Assign the Cognitive Services OpenAI User role for chat completions to a user-assigned managed identity in Azure, or to your own identity for local development, and use DefaultAzureCredential with the https://cognitiveservices.azure.com/.default scope, which runs the same code locally and in Azure5.

Grant a managed identity access to Azure OpenAI
az role assignment create \
  --role "Cognitive Services OpenAI User" \
  --assignee "<identity-id>" \
  --scope "/subscriptions/<subscription-id>/resourceGroups/<resource-group>"

Then remove the fallback. Setting disableLocalAuth to true on the resource, or applying the Azure Policy that requires key access disabled, enforces Entra ID authentication6. Microsoft warns that the change is not immediate: the shared gateway "can continue to accept previously valid keys until its cached configuration refreshes", typically minutes but up to several hours, so verify that a request with the old key returns 401 before you consider keys off6.

OpenAI: federation, expiring keys and creation controls

OpenAI launched Workload Identity Federation on 2026-05-26 and made its mTLS and X.509 variant generally available on 2026-08-298. A trusted workload presents a short-lived external token and receives a short-lived OpenAI access token; the documented sources include Kubernetes, AWS, Microsoft Azure, Google Cloud, Oracle Cloud Infrastructure, GitHub Actions, SPIFFE and X.509 certificates7. Each mapping targets a service account in a project, token exchange never creates a principal or project, and no refresh token is returned: the workload repeats the exchange with a fresh external token7. It is configured under Organization Settings, Security, Workload Identity Provider7.

For keys that remain, two September changes help. Since 2026-09-10 you can set an expiration date when creating a project API key, and admins can cap key lifetime at the organization or project level so new keys must expire within it; since 2026-09-15 admins can restrict key creation to service-account keys or user-owned project keys, or turn it off, with organization restrictions taking precedence and existing keys unaffected8. Set a maximum lifetime now, then work through the keys created before it.

Anthropic: federation with explicit rules

Anthropic's Workload Identity Federation exchanges a JWT from AWS IAM, Google Cloud, GitHub Actions, Kubernetes, SPIFFE, Microsoft Entra ID, Okta or another OIDC issuer for a short-lived sk-ant-oat01-… token bound to a service account, via POST /v1/oauth/token with the RFC 7523 jwt-bearer grant; the SDKs perform the exchange and refresh it before expiry9. Three resources define who may act as whom: a federation issuer (which identity provider), a service account (svac_…), and a federation rule that matches the token's subject, audience or claims and sets the scope and lifetime9. A rule's token_lifetime_seconds ranges from 60 to 86,400 with a default of 3,600, the Console wizard pre-fills 600, and the minted token never outlives twice the remaining life of the identity token presented9.

Anthropic is candid that federation "is only as strong as the upstream identity provider that signs the JWT", and recommends pairing it with that provider's workload binding, conditional access and audit logging9. Two migration traps from its documentation:

  • A leftover key wins. ANTHROPIC_API_KEY sits above the federation variables in every SDK's credential order, so it "silently shadows federation"; unset it in CI secrets, container environments and shell profiles, confirm with ant auth status, then delete the key9.
  • Identity tokens are single-use by default. A token carrying a jti claim cannot be exchanged twice; retry loops and restarted processes that re-present a cached token fail with jti_reused9.

When a static key is unavoidable

Some callers cannot federate: a laptop without a workload identity, a third-party tool that only accepts a key, a SaaS platform calling your provider from outside your cloud. Bound those keys on four axes.

AxisWhat to doProvider controls
LifetimeEvery key has an expiry; nothing is "never"OpenAI expiry and maximum lifetime8; Bedrock credential age2
ScopeOne project, workspace or IAM policy per consumer; inference only, never adminOpenAI projects, Anthropic workspaces, IAM policies
RotationNew key first, deploy, verify, then revoke the old oneGoogle documents this order for Gemini keys4; Anthropic suggests a schedule such as every 90 days10
SpendA provider-side limit on the project or workspaceAnthropic recommends spend limits and regular review of usage10

Keep a written inventory of each static key: who holds it, what it can reach, when it expires. An AI credential inventory covers the format, and least privilege for provider admin keys covers the keys you should never hand out.

How INFRO handles provider credentials and its own keys

INFRO sits between your applications and the provider accounts you own, and today it is one of the callers that holds a static provider credential: you connect an API key per provider (for AWS Bedrock, a long-term Bedrock API key; for Vertex AI, a service-account key from which INFRO signs short-lived access tokens), which INFRO seals with AES-256-GCM, never shows again and uses only for requests routed through it. It does not yet federate into your cloud or provider identity. So bound the credential you give it with the table above: a dedicated project or workspace key, inference permissions only, an expiry, a provider-side spend limit. You can hold several keys per provider in INFRO and replace one through the console or the management API on the next request, which makes rotation with overlap straightforward; replacing a key in INFRO does not revoke the old one at the provider, so revoke it there.

INFRO's own credentials are built to be bounded. Gateway keys carry an expiry, belong to one environment, can be limited to chosen providers and IP ranges (403 ip_not_allowed before any provider call), and rotate with an overlap of none, 1 hour, 24 hours or 7 days, logged in the audit log; management tokens always expire, at most 365 days after creation. See Authentication.

The limit to keep in view: INFRO's budgets and allowlists govern traffic that goes through INFRO. A provider key stolen from anywhere, INFRO included, works directly against the provider until it expires or is revoked. That is the strongest argument for short-lived credentials wherever your own workloads call providers, and for expiry and provider-side limits on every static key that remains.

Summary

Static AI keys are now a choice, not a requirement, for most workloads. Use IAM roles and short-term keys on Bedrock, service accounts and federation on Google Cloud, managed identities with key access disabled on Azure, and Workload Identity Federation on OpenAI and Anthropic. For the keys you cannot remove, set an expiry, narrow the scope, rotate with overlap, cap spend at the provider and write down who holds each one.

Questions readers ask

Can I call Claude or GPT models without an API key?
Yes, from a workload with an identity. Anthropic and OpenAI both offer Workload Identity Federation: your workload presents a token from AWS, Google Cloud, Azure, Kubernetes, GitHub Actions or another OIDC issuer, and receives a short-lived provider token. The same models on Bedrock, Vertex AI or Azure are reachable with that cloud's own identity.
How long do federated AI provider tokens last?
Anthropic's federation rules set 60 to 86,400 seconds, default 3,600, and never longer than about twice the remaining life of the identity token presented. OpenAI's access tokens are capped by the upstream token's remaining lifetime and the rule's lifetime; neither returns a refresh token, so the SDK re-exchanges.
Can I turn off API keys for Azure OpenAI?
Yes. Set disableLocalAuth to true on the resource, or apply the Azure Policy that requires key access disabled. Microsoft warns the gateway may keep accepting old keys for a few minutes to several hours, so confirm with a request using the old key that returns 401.
Do OpenAI API keys expire?
They can. Since 2026-09-10 you can set an expiration date when creating a project API key, and admins can set a maximum key lifetime at the organization or project level. Since 2026-09-15 admins can also restrict who may create keys. Existing keys are not changed by these settings.

From the team that builds it

Where this shows up in INFRO

INFRO is a control plane in front of the provider accounts you already hold. The capabilities below are the parts of it this article touches, each with the documentation that defines its behaviour.

  • Key limits and rotation

    Available with a plan

    Limit a gateway key to chosen providers or IP ranges, and rotate it with an overlap window so the old key keeps working while you deploy the new one.

    Read the documentation for Key limits and rotation
  • Provider connections

    Available with a plan

    Connect provider accounts you already hold. Each credential is encrypted when saved, scoped to your organization and never shown again; applications use INFRO gateway keys instead.

    Read the documentation for Provider connections
  • Management API

    Available with a plan

    Configure an organization as code through /manage/v1 with a scoped, expiring management token: projects, gateway keys, connections, routes, budgets, alerts, cost centers, commitments, guardrails and end-customer caps. Read access from the Startup plan, every write from Team.

    Read the documentation for Management API
  • Environments

    Available with a plan

    Production, staging and development to start, and your own beside them. A connection or route serves one, several or every environment; each gateway key belongs to exactly one, and never reaches a connection outside it.

    Read the documentation for Environments
  • Audit log

    Available with a plan

    Member, key, and policy changes recorded with actor and timestamp, viewable in the console.

    Read the documentation for Audit log
  • Budgets and spend ceilings

    Available with a plan

    A hard cap per organization, project, member, and key, with alerts at your own thresholds.

    Read the documentation for Budgets and spend ceilings

INFRO accounts are self-serve. Provider usage is billed to you by your providers; INFRO charges a software subscription and takes 0% of model spend. See plans.

Sources

Numbered in order of first citation. Each was opened and checked against the claim on the date shown.

  1. 1.Security best practices in IAM (opens in a new tab) — AWS. Accessed Oct 21, 2026.
  2. 2.API keys (Amazon Bedrock) (opens in a new tab) — AWS. Accessed Oct 21, 2026.
  3. 3.Workload Identity Federation (opens in a new tab) — Google Cloud. Accessed Oct 21, 2026.
  4. 4.Using Gemini API keys (opens in a new tab) — Google AI for Developers. Accessed Oct 21, 2026.
  5. 5.Use keyless connections with Azure OpenAI (opens in a new tab) — Microsoft Learn. Accessed Oct 21, 2026.
  6. 6.Disable local authentication in Foundry Tools (opens in a new tab) — Microsoft Learn. Accessed Oct 21, 2026.
  7. 7.Workload identity federation (opens in a new tab) — OpenAI. Accessed Oct 21, 2026.
  8. 8.Changelog (opens in a new tab) — OpenAI. Accessed Oct 21, 2026.
  9. 9.Workload Identity Federation (opens in a new tab) — Anthropic. Accessed Oct 21, 2026.
  10. 10.API key best practices: keeping your keys safe and secure (opens in a new tab) — Anthropic. Accessed Oct 21, 2026.

About this article

On 2026-10-21 we opened AWS's IAM best practices and Amazon Bedrock API key documentation, Google Cloud's Workload Identity Federation overview and Gemini API key page, Microsoft Learn's keyless connections and disable-local-authentication pages, OpenAI's Workload Identity Federation guide and API changelog, and Anthropic's Workload Identity Federation documentation and API key best practices. INFRO behaviour is described from its public documentation and provider registry. Written by the team that builds INFRO.

Last checked against its sources on . The next review is due by . No separate named reviewer is recorded for this article.

How articles are written, sourced and corrected is set out in the editorial standards.