Skip to main content
The OpenRouter Terraform provider lets you manage OpenRouter as infrastructure-as-code. Define platform configuration in code, review changes before applying them, detect drift, and import resources that already exist.

Installation

Add the provider to your Terraform configuration and run terraform init:

Authentication

Authenticate with an OpenRouter Management API key, which starts with sk-or-mgmt-.... Management keys administer resources and cannot spend inference credits. Pass the key to the provider through api_key, for example with a Terraform variable or another secret-management workflow.

Example

This example creates a workspace, an API key assigned to that workspace, and a guardrail:

What it manages

The provider supports the lifecycle of OpenRouter platform resources, including:
  • API keys and workspace configuration
  • Guardrails and spending limits
  • BYOK provider credentials
  • Observability destinations
  • Private endpoints
  • SCIM group mappings
Terraform tracks these resources in state so plans can show configuration drift before you apply a change. Existing resources can be imported into Terraform-managed state.

Resources and data sources

The provider manages, among other resources:
  • API keys and workspace configuration, including workspace members and workspace budgets
  • Guardrails, the guardrail policies a guardrail splits into, and the assignments that attach a policy to a member or an API key. Policies exist in workspace and account scope; assignments are workspace only.
  • BYOK provider credentials
  • Observability destinations
  • Private endpoints
  • SCIM group mappings
  • Organization settings
It also includes data sources for looking up resources and platform information, including API keys, BYOK keys, credits, guardrails, guardrail policies, models, observability destinations, presets, private endpoints, providers, SCIM mappings, and workspaces. The Terraform Registry documentation is the authoritative list of every resource and data source the current release ships; a configuration pinned below version 0.3.310 predates workspace budgets and the guardrail policy resources. The provider source is available on GitHub.