APIs
Why the API entity?
In a typical API gateway setup, each HTTP endpoint is configured as an individual route. This works well for simple use cases, but as your platform grows, you end up with dozens or hundreds of routes that logically belong to the same service — they share the same backends, the same security policies, the same documentation. Managing them individually becomes tedious and error-prone.
The API entity solves this problem by providing a higher-level abstraction that groups everything related to a single API under one roof:
- Multiple routes — define all the endpoints of your API (
GET /users,POST /orders, etc.) in one place, with a shared domain and context path - Shared backends — define backend targets once and reuse them across routes, instead of duplicating target configurations
- Plugin flows — create named plugin chains (authentication, rate limiting, transformations, etc.) and assign them to different routes as needed
- Consumer plans — define who can access your API and how (API keys, JWT, mTLS, OAuth2), with pricing and quotas
- Subscriptions — let developers or machines subscribe to your plans and receive auto-generated credentials
- Lifecycle management — track your API from
stagingthroughpublished,deprecated, andremoved - Testing mode — test draft changes safely before publishing, using a special header to access draft routes
- Versioning and deployments — keep a history of published versions with full snapshots
- Built-in documentation — attach pages, navigation, logos, and banners to power a developer portal
In short, the API entity turns Otoroshi from a route-level proxy into a full API Management platform: you design, secure, publish, version, and document your APIs in one place.
How it works at runtime
When Otoroshi starts or when an API is updated, each API is converted into a set of standard NgRoute objects that the proxy engine uses for request matching and forwarding. This conversion happens transparently:
- Each API route's frontend paths are prefixed with the API's
domainandcontext_path(e.g., a route with path/userson an API with domainapi.example.comand context path/v1becomesapi.example.com/v1/users) - Backend references are resolved — either from the API's local backends or from global stored backends
- The plugin flow referenced by each route is attached as the route's plugin chain
- Published consumer plans inject the appropriate security plugins (API key validation, JWT verification, mTLS checks, etc.) into each route automatically. Whatever the plan kind, the caller is turned into an API key consumer whose quotas and restrictions are enforced at the end of the access validation phase
- If testing mode is enabled, additional draft routes are generated that require a special header to access
This means you get the organizational benefits of the API entity without any runtime overhead — under the hood, Otoroshi's engine processes the same optimized route structures it always has.
APIs vs. Routes — when to use which
Otoroshi offers two levels of abstraction for configuring your HTTP traffic, and they serve different purposes:
Routes: low-level HTTP routing
A route is a low-level, flexible building block. It gives you direct control over every aspect of HTTP proxying: exact domain matching, path patterns, headers, the full plugin chain, backend targets, TLS settings, etc. There are no constraints — you can wire anything to anything.
Routes are the right choice when:
- You need maximum flexibility and fine-grained control over how a specific request is handled
- You are proxying traffic that doesn't fit the "managed API" model (static assets, internal redirects, catch-all rules, WebSocket tunnels, TCP proxying, etc.)
- You want to set up a quick one-off reverse proxy rule without the overhead of lifecycle management
APIs: structured API Management
An API is a higher-level, more opinionated entity built on top of routes. It adds structure and guardrails: a shared domain, a context path, a lifecycle (staging → published → deprecated → removed), consumer plans, subscriptions, versioning, deployments, and documentation.
This structure is deliberate — it trades some of the route-level flexibility for consistency and governance:
- All routes in an API share the same domain and context path, so your URL scheme stays coherent
- Security policies are defined as consumer plans rather than per-route plugin configurations, making it easier to reason about who has access to what
- Lifecycle states prevent accidental exposure of work-in-progress endpoints
- Subscriptions and credential generation provide a self-service workflow for API consumers
- Deployment history gives you traceability of what was published and when
APIs are the right choice when:
- You are exposing a service to external or internal consumers and want to manage access in a structured way
- You need lifecycle management, versioning, and deployment tracking
- You want to offer subscription plans with auto-generated credentials (API keys, JWT, OAuth2, mTLS)
- You are building a developer portal
Under the hood, it's all routes
The key insight is that APIs are ultimately compiled down to routes at runtime. An API is a management-layer abstraction — it doesn't introduce a different proxy engine. When you create an API with 5 endpoints, Otoroshi generates 5 NgRoute objects behind the scenes, with the domain/context path prefixed, the backends resolved, and the consumer plan security plugins injected. So the choice between APIs and routes is really about how you want to organize and govern your configuration, not about runtime behavior.
UI page
You can find all APIs here
API entity properties
An API is the top-level entity that groups together routes, backends, flows, documentation, plans, subscriptions, and clients.
| Property | Type | Description |
|---|---|---|
id | string | Unique identifier of the API |
name | string | Display name of the API |
description | string | Description of the API |
domain | string | The domain on which the API is exposed (e.g., api.mydomain.com) |
context_path | string | The base path prefix for all routes in this API (e.g., /api/v1) |
version | string | Current version of the API (e.g., 1.0.0) |
versions | array of string | List of all versions of this API |
enabled | boolean | Whether the API is active and serving traffic |
state | string | Lifecycle state: staging, published, deprecated, or removed |
blueprint | string | API type: REST, GraphQL, gRPC, Http, or Websocket |
debug_flow | boolean | Enable debug flow logging for all routes |
capture | boolean | Enable request/response capture |
export_reporting | boolean | Enable detailed reporting export |
groups | array of string | Service groups this API belongs to |
tags | array of string | Free tags for categorization |
metadata | object | Free key/value metadata |
routes | array of ApiRoute | The routes that compose this API |
backends | array of ApiBackend | Backend definitions local to this API |
flows | array of ApiFlows | Plugin flow chains |
clients_backend_config | array of ApiBackendClient | Backend client configurations |
documentation | ApiDocumentation | API documentation and developer portal configuration |
deployments | array of ApiDeployment | Deployment history |
clients | array of ApiClient | Registered API clients |
testing | ApiTesting | Testing/draft mode configuration |
API lifecycle
An API goes through the following lifecycle states:
staging --> published --> deprecated --> removed
| State | Description |
|---|---|
staging | The API is being designed. Only draft/testing routes are served (if testing is enabled). |
published | The API is live and serving traffic. Plans can accept subscriptions. |
deprecated | The API is still serving traffic but is marked for removal. No new subscriptions should be created. |
removed | The API is deactivated. No traffic is served. |
An API written by a remote catalog takes its state from the source of the catalog: each deploy of the catalog is a deploy of the API, without a draft.
API blueprints
The blueprint field indicates the type of API being managed:
- REST: Standard RESTful HTTP APIs
- GraphQL: GraphQL APIs
- gRPC: gRPC services
- Http: Generic HTTP services
- Websocket: WebSocket-based APIs
Routes
An API is composed of multiple routes. Each route describes an HTTP endpoint exposed by the API (e.g., GET /users, POST /orders).
A route is composed of a frontend (describing the entry point: domain, path, methods, headers), a reference to a backend, and a reference to a flow (plugin chain).
| Property | Type | Description |
|---|---|---|
id | string | Unique identifier of the route |
name | string | Display name of the route (optional) |
enabled | boolean | Whether this route is active (default: true) |
frontend | object | Frontend configuration (domains, paths, headers, methods, query, strip_path, exact) |
backend | string | Reference to a backend ID (either a local API backend or a global stored backend) |
flow_ref | string | Reference to a flow ID from this API's flows list |
The route's frontend paths are automatically prefixed with the API's domain and context_path. For example, if the API has domain: api.example.com and context_path: /v1, and a route has a frontend path /users, the effective matching path will be api.example.com/v1/users.
A route can be enabled or disabled independently of the API's activation.
Route JSON example
{
"id": "route_users_list",
"enabled": true,
"name": "List users",
"frontend": {
"domains": ["oto.tools/users"],
"strip_path": true,
"exact": false,
"headers": {},
"query": {},
"methods": ["GET"]
},
"backend": "api_backend_abc123",
"flow_ref": "default_plugin_chain"
}
Backends
A backend represents a list of target servers, along with its load balancing, health checks, and connection settings.
Backends can be defined locally within the API (in the backends array) or reference a global stored backend by its ID. This makes backends reusable across multiple APIs and routes.
| Property | Type | Description |
|---|---|---|
id | string | Unique identifier of the backend |
name | string | Display name of the backend |
backend | object | Full backend configuration (targets, root, rewrite, load balancing, health checks, TLS, etc.) following the NgBackend format |
client | string | Reference to a backend client configuration ID from clients_backend_config |
Backend JSON example
{
"id": "api_backend_abc123",
"name": "Users service backend",
"backend": {
"targets": [
{
"id": "target_1",
"hostname": "users-service.internal",
"port": 8080,
"tls": false,
"weight": 1
}
],
"root": "/",
"rewrite": false,
"load_balancing": { "type": "RoundRobin" }
},
"client": "default_backend_client"
}
Backend clients
Backend clients define the HTTP client configuration used when connecting to backend targets. They are referenced by backends using the client field.
| Property | Type | Description |
|---|---|---|
id | string | Unique identifier |
name | string | Display name |
client | object | Client configuration (retries, timeouts, circuit breaker, connection pool, etc.) following the NgClientConfig format |
Backend client JSON example
{
"id": "default_backend_client",
"name": "Default client",
"client": {
"useCircuitBreaker": true,
"retries": 1,
"maxErrors": 20,
"retryInitialDelay": 50,
"backoffFactor": 2,
"callAndStreamTimeout": 120000,
"callTimeout": 30000,
"idleTimeout": 60000,
"globalTimeout": 30000,
"connectionTimeout": 10000
}
}
Flows
A flow is a named collection of plugins. Plugins are applied between the frontend and the backend (and vice versa) during request processing. Each route references a flow by ID.
| Property | Type | Description |
|---|---|---|
id | string | Unique identifier of the flow |
name | string | Display name of the flow |
plugins | object | Plugin chain following the NgPlugins format |
A default flow named default_plugin_chain is automatically created with the OverrideHost plugin. You can add multiple flows to apply different plugin chains to different routes within the same API.
You can check the list of available plugins here.
Flow JSON example
{
"id": "authenticated_flow",
"name": "Authenticated flow",
"plugins": [
{
"plugin": "cp:otoroshi.next.plugins.OverrideHost",
"enabled": true,
"include": [],
"exclude": [],
"config": {}
},
{
"plugin": "cp:otoroshi.next.plugins.ApikeyCalls",
"enabled": true,
"include": [],
"exclude": [],
"config": {}
}
]
}
Documentation
The API documentation subsystem powers developer portal experiences. It supports pages, navigation sidebars, search, banners, logos, and external content sources.
| Property | Type | Description |
|---|---|---|
enabled | boolean | Whether the documentation is active |
source | object | Optional remote source to fetch documentation content (URL, headers, timeout, follow_redirects) |
home | object | Home page resource |
logo | object | Logo resource |
references | array | List of external reference links (title, description, link, icon) |
resources | array | List of documentation resources/pages |
navigation | array | Sidebar navigation structure (categories and links) |
redirections | array | URL redirections (from -> to) |
footer | object | Footer resource (optional) |
search | object | Search configuration (enabled: boolean) |
banner | object | Banner resource (optional) |
plans | array of ApiDocumentationPlan | Subscription plans with access modes and pricing |
metadata | object | Documentation metadata |
tags | array of string | Documentation tags |
Documentation resources
Each resource in the documentation can contain:
| Property | Type | Description |
|---|---|---|
path | array of string | Path segments for URL routing |
title | string | Page title |
description | string | Page description |
content_type | string | Content type (default: text/markdown) |
text_content | string | Inline text content |
json_content | object | Inline JSON content |
base64_content | string | Base64-encoded binary content |
url | string | Remote URL to fetch content from |
site_page | boolean | Whether this resource is a standalone site page |
transform | string | Content transformation to apply |
Plans
Plans (also referred to as consumers in the UI) define security policies and pricing for API access. Each plan specifies an access mode that determines how clients authenticate when calling the API.
| Property | Type | Description |
|---|---|---|
id | string | Unique identifier of the plan |
name | string | Display name of the plan |
description | string | Description of the plan |
status | string | Plan status: staging, published, deprecated, or closed. See plan statuses |
access_mode_configuration_type | string | Access mode type (see below) |
access_mode_configuration | object | Access mode configuration (depends on type) |
rateLimiting | object | Rate limiting of the plan: { "strategy": { ... } }. Every consumer of the plan is rate limited with that strategy. Defaults to the legacy strategy with the default quotas |
plugins | object | Plugin chain applied for the consumers of this plan. See plan plugins |
validation | object | How subscriptions are validated: { "kind": "auto" | "manual" | "webhook" | "workflow" } |
visibility | object | Visibility of the plan in the developer portal: { "kind": "public" | "semi_public" | "private" | "custom" } |
pricing | ApiPricing | Pricing configuration |
tags | array of string | Tags |
metadata | object | Metadata |
selection | array of { "path", "value" } | On a keyless, jwt, mtls or oauth2-remote plan, the JSON path conditions a call has to meet for the plan to apply to it. Refused on apikey and oauth2-local plans (400 invalid_plan). Absent: every call the plan can identify |
counter_failure | object | { "mode": "deny" | "allow", "timeout": <ms> }: what happens when the counter of the quotas of the plan cannot be reached. deny, the default, answers 503 errors.quotas.unavailable; allow lets the call through uncounted (quota_check_skipped in its analytics). With a timeout, a counter that has not answered by then is a failure |
circuit_breaker_scope | string | route (default): the circuit breaker of the backend is shared by every caller of the route; consumer: each consumer of the plan gets its own, so that one consumer making the backend fail does not open it for the others. Unused consumer breakers are forgotten after otoroshi.circuit-breakers.consumer-scope-ttl (10 minutes) |
Choosing the plan of a call
Between plans of the same kind, the order of plans decides: the first one that identifies the caller wins (see
several plans on the same route). A selection lets a
plan pass on a call: all its conditions have to hold, evaluated against
{
"request": { "method": "GET", "path": "/users", "domain": "my-api.oto.tools", "ip": "1.2.3.4",
"headers": { "x-partner-id": "acme" }, "query": { "page": "1" } },
"token": { "client_id": "client-1", "tier": "gold" },
"certificate": { "subject_dn": "CN=client-1", "issuer_dn": "CN=my-ca", "serial_number": "1234" },
"client_id": "client-1"
}
where token holds the claims of the token of a jwt or an oauth2-remote plan, certificate the client certificate
of an mtls plan, and client_id the client id the plan read, without prefix. A plan whose selection fails for a call
identifies no one, and the next plan gets the call:
"plans": [
{ "id": "plan_gold", "access_mode_configuration_type": "jwt", "selection": [{ "path": "$.token.tier", "value": "gold" }], ... },
{ "id": "plan_free", "access_mode_configuration_type": "jwt", ... }
]
Plan statuses
A plan is served when it is published or deprecated: it installs its access plugins on the routes of the API,
and its consumers are identified and enforced.
| Status | On the routes of the API | Subscriptions |
|---|---|---|
staging | not served: installs nothing | can be created |
published | served | can be created |
deprecated | served: its consumers keep calling, with their quotas | no new subscription; the existing ones can be updated |
closed | not served | deleted with their API keys |
An API with no published or deprecated plan refuses the calls that no plugin of its flows identified (401, with
apikey_rejection_reason: the api has no published plan): putting its last plan in staging, closing it or removing it
never opens the API. To serve anonymous callers, publish a keyless plan (with create_if_missing: false if no API key
should be stored per caller).
Access modes
Whatever the access mode, a served plan turns the caller into a consumer, and a consumer is always an API key: the quotas, restrictions and rotation of the plan are enforced the same way for a public plan and for a plan asking for client credentials. See API consumers and plugin flows for the whole picture.
| Mode | Description | Plugins applied |
|---|---|---|
keyless | No credential required. The consumer is derived from an expression, the caller IP address by default | NgExpressionApikeyExtractor |
apikey | Requires a valid API key. Configurable key patterns, restrictions, quotas, and rotation | ApikeyCalls |
jwt | Requires a valid JWT token. The consumer is the client id claim of the token | NgJwtApikeyExtractor |
mtls | Requires a TLS client certificate matching the configured subject/issuer patterns | NgClientCertApikeyExtractor |
oauth2-local | OAuth2 client credentials flow with local token generation. Clients obtain a JWT to call other routes | ApikeyCalls + client credentials endpoint |
oauth2-remote | OAuth2 token verified against the OIDC settings of an auth. module. The consumer is the client id claim of the token | NgOidcApikeyExtractor |
Every route of a published or deprecated API ends with NgApiConsumerEnforcer, whatever its plans. It runs at the
plugin index 1000 of the access validation phase, requires a consumer, and is the only place where a call is counted
against the quotas of the plan. On an API without a published or deprecated plan, it only lets through the callers a
plugin of the flows of the API identified (an auth. module, an ApikeyCalls of the flow...), without enforcing their
API key again: that plugin already applied its own checks and quotas.
The access validators run in the order of their plugin index, and the ones without an index after all the others: a
plugin of a flow has to run before the consumer enforcer, with an index below 1000, for the enforcer to see the
caller it identified. The plugins of a flow edited from the UI always get an index.
All the access modes but apikey and oauth2-local generate an API key for a consumer they have
never seen, and they all share the create_if_missing flag for that. When it is on, the default,
the generated API key is persisted and shows up in the UI. When it is off, the identity only lives
for the duration of the call. In both cases the caller is served and its consumption is counted.
A jwt, mtls or oauth2-remote plan with subscription_required generates nothing: only the consumers whose
subscription to the plan is enabled, and carries the client id they call with, are served. Any
other caller is not identified by the plan: another plan of the API can still identify it (a keyless plan, as for any
call without credentials), otherwise the call gets 401, and the analytics of the call tell which client id is not
subscribed to which plan.
Keyless access mode configuration
| Property | Type | Default | Description |
|---|---|---|---|
expr | string | ${req.ip} | Expression building the consumer identity of a public call |
create_if_missing | boolean | true | Persist the generated API key |
restrictions | object | no restriction | The restrictions of the API key of each consumer: the paths and methods it is allowed, forbidden or not found on, enforced at the end of the access validation. Changing them, or the rateLimiting of the plan, rewrites the API keys already generated for the plan |
A missing value resolves to no-header-<field> and puts every such caller on one shared quota. Use
an empty default (${req.headers.x-consumer:}) to have those calls rejected instead.
JWT access mode configuration
| Property | Type | Default | Description |
|---|---|---|---|
verifier | string | ID of the JWT verifier validating the token | |
client_id_path | string | client_id | Claim holding the client id of the consumer. A JSON path such as $.azp works too |
create_if_missing | boolean | true | Persist the generated API key |
subscription_required | boolean | false | Only the consumers with an enabled subscription to the plan, whose client_id is the one they call with, are served; the others get 401. create_if_missing is then ignored. Off, every valid token (or certificate) is a consumer of the plan |
restrictions | object | no restriction | The restrictions of the API key of each consumer: the paths and methods it is allowed, forbidden or not found on, enforced at the end of the access validation. Changing them, or the rateLimiting of the plan, rewrites the API keys already generated for the plan |
mTLS access mode configuration
| Property | Type | Default | Description |
|---|---|---|---|
trusted_ca_refs | array of string | [] | The ids of the certificates of the store (authorities) that must have signed the client certificate: its chain has to lead to one of them. Empty, the authority is not checked by the plan |
regex_subject_dns | array of string | [] | Regex patterns the subject DN of the client certificate may match |
regex_issuer_dns | array of string | [] | Regex patterns the issuer DN may match |
dn_match | all or any | any | How the two lists of patterns combine: all, every list that is not empty must match; any, one of them is enough. The backoffice writes all for a new mTLS plan |
client_id_field | string | null | DN attribute holding the client id (UID, CN, ...). Left empty, the identity is derived from the whole subject and the serial number. A certificate missing the named attribute is rejected |
create_if_missing | boolean | true | Persist the generated API key |
subscription_required | boolean | false | Only the consumers with an enabled subscription to the plan, whose client_id is the one they call with, are served; the others get 401. create_if_missing is then ignored. Off, every valid token (or certificate) is a consumer of the plan |
restrictions | object | no restriction | The restrictions of the API key of each consumer: the paths and methods it is allowed, forbidden or not found on, enforced at the end of the access validation. Changing them, or the rateLimiting of the plan, rewrites the API keys already generated for the plan |
A list of patterns is satisfied when one of its patterns matches, the subject list against the subject DN of the client certificate, the issuer list against its issuer DN. With dn_match: all, every list that is not empty must be satisfied; with any, one of them is enough. When both lists are empty, any certificate is accepted, whatever dn_match says.
The authorities that may issue a client certificate are first decided by the TLS handshake, and its trust store is the one of the whole gateway: every certificate of the store plus the CAs of the JDK, unless tlsSettings.trustedCAsServer and tlsSettings.includeJdkCaServer of the global configuration say otherwise. In the permissive trust mode (tlsSettings.strictBackendServerValidation off, what an installation upgraded from a version without that field reads), the handshake accepts any client chain. A subject pattern alone then accepts a certificate with that subject from any of those authorities, and an issuer pattern only compares text with the issuer field of the certificate, which anyone can write in a certificate of their own.
trusted_ca_refs is what ties a plan to its authority. When it is not empty, the chain the client sent (its certificate, then the intermediates as sent) is validated against those certificates of the store with PKIX at the current date, before the DN patterns are read, whatever the trust store and the trust mode of the handshake. A chain that does not lead to one of them is not identified by the plan, and no API key is generated. Revocation is not checked on the chain (it is the business of the handshake and of the store), but a revoked authority is not trusted anymore: when none of the ids is a certificate of the store that is not revoked, deleted or unknown, every certificate is refused and a warning is logged. The ids are not checked to exist when the API is written, since an import or a catalog may write the API before its certificates.
{
"access_mode_configuration_type": "mtls",
"access_mode_configuration": {
"trusted_ca_refs": ["partner-ca"],
"regex_subject_dns": [".*CN=client-1.*"],
"regex_issuer_dns": [".*CN=Partner CA.*"],
"dn_match": "all",
"client_id_field": "CN"
}
}
OAuth2 remote access mode configuration
| Property | Type | Default | Description |
|---|---|---|---|
verifier | string | ID of the auth. module whose OIDC settings validate the token | |
client_id_path | string | client_id | Claim holding the client id of the consumer (client_id, azp or cid depending on the vendor) |
fetch_user | boolean | false | Call the userinfo endpoint of the module and store the profile of the token holder in a metadata of the API key. The call stays a consumer call, no user session is attached to it |
user_metadata_key | string | user_profile | Metadata key holding that profile |
create_if_missing | boolean | true | Persist the generated API key |
issuer | string | The iss a token must carry, compared exactly: the issuer of the discovery document of the authorization server. Not checked when absent | |
audiences | array of string | [] | The token must carry at least one of them in its aud claim. A token without aud is refused. Not checked when empty |
subscription_required | boolean | false | Only the consumers with an enabled subscription to the plan, whose client_id is the one they call with, are served; the others get 401. create_if_missing is then ignored. Off, every valid token (or certificate) is a consumer of the plan |
restrictions | object | no restriction | The restrictions of the API key of each consumer: the paths and methods it is allowed, forbidden or not found on, enforced at the end of the access validation. Changing them, or the rateLimiting of the plan, rewrites the API keys already generated for the plan |
A token refused for its issuer or its audience is not identified by the plan, and nothing is minted for it: another
plan of the API can still identify the call (a second oauth2-remote plan of the same module for another audience
for instance), otherwise the call answers 401. The reason is written to the analytics of the call, under
token_rejection_reason.
Without issuer nor audiences, the plan accepts any token signed with the keys of the auth. module: an
authorization server signs the tokens of all its clients and all its resource servers with the same keys, and some
multi-tenant servers sign the tokens of all their tenants with one key set. Tokens issued for other clients, for
other APIs or for other tenants of the same server are accepted and turned into consumers of the plan. Set at least
the audience of the API.
Apikey access mode configuration
| Property | Type | Description |
|---|---|---|
clientIdPattern | string | Regex pattern for generated client IDs |
clientNamePattern | string | Regex pattern for generated client names |
description | string | Description for generated API keys |
authorizedEntities | array | Entities the API key is authorized on |
enabled | boolean | Whether generated keys are enabled |
readOnly | boolean | Whether generated keys are read-only |
allowClientIdOnly | boolean | Allow authentication with client ID only (no secret) |
constrainedServicesOnly | boolean | Restrict to constrained services only |
restrictions | object | Access restrictions (allowed/forbidden paths and methods) |
rotation | object | Key rotation configuration (enabled, rotationEvery, gracePeriod) |
validUntil | number | Expiration timestamp (milliseconds), the same for every key of the plan |
validity | number | How long a key is valid, in milliseconds, counted from the first time it is enabled. Combined with validUntil, the key expires at the earlier of the two |
tags | array of string | Tags for generated keys |
metadata | object | Metadata for generated keys |
Validity of the keys
With a validity, each key of the plan gets its own expiry, counted from the moment it is first enabled: the creation of an enabled subscription, or the confirmation of a pending one (the validity does not run while a subscription waits for its approval). The key gets the earlier of that moment plus the validity and the validUntil of the plan, and the start of its validity in its validity_started_at metadata.
From then on, the validUntil of the key is its own. Writing it renews or shortens the key, and that date survives the updates of the subscription and of the plan, capped by the validUntil of the plan when that one is earlier. Changing or removing the validity of the plan never extends nor resets the keys already started: it applies to the keys not started yet. Without validity, the validUntil of the plan is put back on the keys at every update, as before.
"access_mode_configuration": {
"enabled": true,
"validity": 7776000000
}
The keys of this plan are valid 90 days from their subscription. An api key past its validUntil is not active anymore: its calls are refused.
Rate limiting
The rateLimiting property of a plan holds the throttling strategy handed over to every consumer of
the plan, whether it got its API key through a subscription or was generated on the fly by the access
mode. A plan without an explicit strategy falls back on the legacy one with the default quotas, which
is what an API key created by hand gets.
{
"rateLimiting": {
"strategy": {
"id": "LegacyThrottlingStrategyConfig",
"quota": { "window": 100, "daily": 10000, "monthly": 300000 }
}
}
}
Plan plugins
A plan can bring its own plugins. They are applied on top of the plugin chain of the route, for the consumers of that plan only. See API consumers and plugin flows.
| Property | Type | Default | Description |
|---|---|---|---|
plugins | array | [] | Plugin chain, same format as the plugins of a route |
flow_ref | string | null | ID of one of the flows of the API to use instead of listing the plugins here. An inline chain extends the referenced flow, it does not replace it |
overrides | boolean | false | Replace the plugins of the route instead of extending them. The pre-route and access validation plugins that already ran are kept, as are the global plugins |
{
"plugins": {
"overrides": false,
"flow_ref": "authenticated_flow",
"plugins": [
{
"plugin": "cp:otoroshi.next.plugins.AdditionalHeadersOut",
"enabled": true,
"include": [],
"exclude": [],
"config": {
"headers": { "X-Plan": "${apikey.api.plan}" }
}
}
]
}
}
Plan JSON example
{
"id": "plan_free_tier",
"name": "Free Tier",
"description": "Free access with rate limiting",
"status": "published",
"access_mode_configuration_type": "apikey",
"access_mode_configuration": {
"enabled": true,
"readOnly": false,
"allowClientIdOnly": false,
"constrainedServicesOnly": false,
"restrictions": {
"enabled": false
},
"rotation": {
"enabled": false,
"rotationEvery": 744,
"gracePeriod": 168
},
"tags": [],
"metadata": {}
},
"rateLimiting": {
"strategy": {
"id": "LegacyThrottlingStrategyConfig",
"quota": { "window": 10, "daily": 1000, "monthly": 10000 }
}
},
"plugins": {
"plugins": [],
"overrides": false,
"flow_ref": null
},
"validation": { "kind": "auto", "config": {} },
"visibility": { "kind": "public", "config": {} },
"pricing": {
"id": "pricing_free",
"name": "Free",
"enabled": true,
"price": 0,
"currency": "EUR",
"params": {}
},
"tags": [],
"metadata": {}
}
Pricing
Plans can include pricing information for monetization purposes.
| Property | Type | Description |
|---|---|---|
id | string | Unique identifier |
name | string | Pricing plan name |
enabled | boolean | Whether pricing is active |
price | number | Price amount |
currency | string | Currency code (e.g., EUR, USD) |
params | object | Additional pricing parameters |
Subscriptions
End-users (developers, portals, machines) can subscribe to published plans. A subscription contains information about the subscriber and references to the generated credentials (API key, certificate, JWT, etc.).
| Property | Type | Description |
|---|---|---|
id | string | Unique identifier |
name | string | Display name |
description | string | Description |
status | string | Only enabled gives access: with any other status (pending until it is confirmed, disabled, deprecated, or a custom value) the API keys of the subscription are disabled. Defaults to disabled |
api_ref | string | Reference to the parent API |
plan_ref | string | Reference to the plan |
owner_ref | string | Reference to the subscribing client |
subscription_kind | string | Kind of subscription: apikey, mtls, keyless, oauth2-local, oauth2-remote, jwt. It has to be the access mode of the plan |
token_refs | array of string | References to generated credentials (API key IDs, certificate IDs, etc.), and to the shared credential the subscription shares, if any (see One API key for several APIs) |
client_id | string | For a jwt, mtls or oauth2-remote subscription: the client id its consumer calls with, as the plan reads it, without prefix. See below |
dates | object | Lifecycle timestamps (see below) |
tags | array of string | Tags |
metadata | object | Metadata |
A subscription is refused with a 400 when its subscription_kind is not the access mode of its plan.
A subscription to an apikey or an oauth2-local plan is given an API key built from the plan, and
referenced in token_refs as {"apikey": "<client id>"}: the consumers of these plans call with an
API key, and a subscription is the only way to get one. The keyless access mode builds its consumer at call time, its
subscriptions have nothing to generate.
The jwt, mtls and oauth2-remote access modes build their consumer at call time too, as the API key
<prefix><client id> (jwt_<api id>_<plan id>_, mtls_<api id>_<plan id>_ or oauth2_<api id>_<plan id>_, the client id being the claim at
client_id_path of the token, or the client_id_field of the certificate). A subscription to one of these plans
with a client_id provisions that very API key, and references it in token_refs: the subscription then decides for
that consumer. A key the plan already minted on the fly for it is taken over (same client id and secret), a key of
another API or of another plan is not. Two subscriptions of a plan cannot share a client_id, and the client_id of a
subscription cannot change (400): delete the subscription and create another one. A subscription without
client_id provisions nothing, and its consumer keeps being identified at call time.
The API key of a subscription follows its status: it is enabled only while the subscription is enabled, and disabled
as soon as the subscription is set to any other status. POST .../apis/{apiId}/plans/{planId}/subscribe saves the subscription
pending whatever its body says, with its API key disabled: POST .../apis/{apiId}/subscriptions/{subId}/confirm
enables both. Both work on the API of their path, whose rights they require: subscribe refuses a body whose api_ref
or plan_ref is not the API or the plan of the path (400), and confirm does not find the subscription of another
API (404).
A subscription only manages the API keys it minted: the ones whose apiRef is the subscription, and the ones minted
before the API keys had an apiRef (authorized on the API of the subscription, with the metadata a subscription writes on
its keys). An API key of another subscription, or an API key no subscription minted, named in its token_refs is left
alone: an update of the subscription or of its plan does not rebuild it, a deletion does not revoke it, and a new
subscription does not list it in its token_refs.
Deleting a subscription (by id, all of them, in bulk, or when a remote catalog or the Kubernetes job removes it) deletes
the API keys it minted: its consumers cannot call the API anymore. The API key of a jwt, mtls or oauth2-remote subscription is disabled, not deleted: the plan
would mint it again, enabled, at the next call. A subscription whose API keys could not be revoked is kept, and the
deletion answers a 500. Removing a plan from an API deletes its subscriptions and revokes their API keys in the same
way. Closing a plan deletes its subscriptions and their API keys, whatever their kind. Deleting an API deletes its
subscriptions, the API keys they hold, and the API keys its plans generated for their consumers.
One API key for several APIs
A consumer can call several APIs with one credential (one client id and one secret), each API through a subscription of
its own, with the quotas, the restrictions and the plugins of its own plan. That credential is a shared credential:
an API key K that belongs to the consumer and to no subscription, authorized on nothing by itself, marked with
sharedCredential.owner, the owner_ref of the subscriptions of that consumer.
{
"clientId": "K",
"clientSecret": "...",
"clientName": "credential of client_acme",
"authorizedEntities": [],
"sharedCredential": { "owner": "client_acme" }
}
A subscription shares it with an entry of its token_refs, at its creation:
{
"api_ref": "api_orders",
"plan_ref": "plan_gold",
"owner_ref": "client_acme",
"subscription_kind": "apikey",
"token_refs": [{ "shared": true }]
}
{"shared": true}takes the credential of the owner of the subscription: the shared credential whose owner is itsowner_ref, located where the subscription is (the same tenant, the same teams), that a subscription created (sharedCredential.minted). When there is none, it is created with the subscription, where the subscription is located: the first subscription of a consumer creates its credential, the next ones located there share it. Theowner_refis free text, and a subscription creates the credential of any owner where its author writes: the one located in other teams is never taken that way, nor is a shared credential written by hand for an owner. They are shared by the subscriptions that name them, and only a super admin writes amintedone by hand (an import, a restoration). An owner with several credentials there names the one it shares (400otherwise). Subscriptions of an owner created at the same time in the same location share one credential too: the first one creates it.{"apikey": "K", "shared": true}names the credential, created beforehand through the API keys.
The subscription gets an API key of its own, K_b, built from its plan exactly like any other, and listed next to the
credential: [{"apikey": "K", "shared": true}, {"apikey": "K_b"}]. K_b is an alias: its apiRef.credential is
K. The consumer calls the API of the subscription with the client id and the secret of K, and the call is identified as
K_b: the throttling strategy and the quotas of the plan of the subscription (its own counter), its restrictions, its
plugins, and the apiRef of the gateway events are the ones of K_b, whose apiRef.credential tells the credential the
consumer called with. The backend of each API sees the client id of its own alias. Called with its own client id, an
alias is refused: it has no secret of its own. The biscuit extractors and the legacy API key extractors do not resolve
the credential of an alias: they find no API key for it, and the plugins of the old engine that check a secret against
the API key itself (client credentials, API key auth module) refuse the one of an alias.
- Only an
apikeyor anoauth2-localsubscription shares a credential, one at most, and only a shared credential whose owner is itsowner_ref, that no other subscription to the same API shares yet. The API key of a subscription is never shared. Otherwise the subscription is refused with a400. Of several subscriptions sharing a credential on one API created at the same time, one only is created, the other ones are refused with a400. The draft of a subscription shares nothing (400): its API keys are real ones, they would open the live API. - The author of the subscription must be allowed to write the credential, named or not: a user who cannot is refused
with a
400by the admin API, a403bysubscribe, and cannot update or delete such a subscription either. Theowner_ref, free text, is not enough. With{"shared": true}, the credential is the one located where the subscription is, created there when there is none: the author must be allowed to write API keys there, whether the credential exists yet or not. - The shared entry is given at the creation and never changes, nor do the API and the owner of the subscription
(
400): delete the subscription and create another one. - The credential is its own: its secret, its rotation, its expiry and its
enabledflag are set onK, and are the ones of every call. A new secret ofKcalls every API, and a disabled or expiredKcalls none, like any API key. The validity of the plan of a subscription applies to its alias, which has no rotation. - Suspending, closing or deleting a subscription disables or deletes its own alias only: the other APIs are still
called. The credential is never updated, disabled or deleted with a subscription, not even with the last one: it is
deleted by hand. Deleting
K, by any means, deletes its aliases. The subscriptions that sharedKstay, without an alias: they call nothing, and are still updated and deleted by the ones who can write them. They still nameKand their alias: only a super admin can create an API key under the client id of a credential that aliases still name, or under a client id such a subscription still names (an import, a restoration). - An API key is created as a shared credential, with no
authorizedEntitiesand noapiRef, and stays one, for the same owner (400).apiRef.credentialis written by the subscription that mints the alias, and never changes (400). An alias only serves while its credential is a shared credential, the subscription named by itsapiRefexists, shares that credential and lists the alias in itstoken_refs, and on the API it is authorized on: an alias written through the API keys (which requires the rights to write its credential) serves nothing.
A call made with K looks for its alias on the API in the proxy state, next to the API keys: it never reads the
datastore, and a call that uses no alias costs what it cost before. An alias serves once the proxy state
is synchronized, like any new API key.
The jwt, mtls and oauth2-remote plans need none of this: one token or one certificate already calls several
APIs, each plan identifying the consumer with an API key of its own.
Subscription dates
| Property | Type | Description |
|---|---|---|
created_at | number | Timestamp when subscription was created |
processed_at | number | Timestamp when subscription was processed |
started_at | number | Timestamp when subscription became active |
paused_at | number | Timestamp when subscription was paused |
ending_at | number | Timestamp when subscription will end |
closed_at | number | Timestamp when subscription was closed |
Subscription JSON example
{
"id": "subscription_abc123",
"name": "ACME Corp subscription",
"description": "Free tier subscription for ACME Corp",
"status": "enabled",
"api_ref": "api_users_service",
"plan_ref": "plan_free_tier",
"owner_ref": "client_acme",
"subscription_kind": "apikey",
"token_refs": [{ "apikey": "apikey_xyz789" }],
"dates": {
"created_at": 1710000000000,
"processed_at": 1710000000000,
"started_at": 1710000000000,
"paused_at": 1710000000000,
"ending_at": 1710000000000,
"closed_at": 1710000000000
},
"tags": [],
"metadata": {}
}
API clients
Clients represent the consumers that subscribe to your API. They are lightweight entities used to identify subscribers.
| Property | Type | Description |
|---|---|---|
id | string | Unique identifier |
name | string | Client name |
description | string | Description |
tags | array of string | Tags |
metadata | object | Metadata |
Testing
The testing configuration allows you to test draft routes before publishing the API. When testing is enabled, Otoroshi generates special routes from the API's draft with a custom header requirement.
| Property | Type | Description |
|---|---|---|
enabled | boolean | Whether testing mode is active |
headerKey | string | Header name required to access draft routes (default: X-OTOROSHI-TESTING) |
headerValue | string | Expected header value (auto-generated UUID) |
When testing is enabled:
- Draft routes are built from the latest saved draft of the API
- Each draft route requires the testing header (
X-OTOROSHI-TESTING: <value>) to be accessible - This allows you to test changes without affecting published routes
Trying a request on a route of the API
The admin API sends a request through a route of a published or deprecated API and answers its response with the execution report of the call, like the tester of the backoffice. It is the way to see, from a script or a CI pipeline, which plan extractor identified the caller, why the api consumer enforcer refused it, and which plugins of the plan ran:
curl -X POST 'http://otoroshi-api.oto.tools:8080/apis/apis.otoroshi.io/v1/apis/my-api/routes/route_list_users/_tryit' \
-u admin-api-apikey-id:admin-api-apikey-secret \
-H 'Content-Type: application/json' \
-d '{
"headers": {
"Otoroshi-Client-Id": "my-client-id",
"Otoroshi-Client-Secret": "my-client-secret"
}
}'
Without a path, the request calls the path of the route under the context path of the API. The admin API key has to be able to read the API. The routes of an API in staging, a route of another API, or a route the API does not hold are not found (404).
The extractors of the plans and the api consumer enforcer are access validators: the call-access-validator-plugins step of the report lists each of them, allowed or denied with the status of the refusal. The request is sent from 127.0.0.1, which is what the ${req.ip} expression of a keyless plan sees. The body of the trial and the rest of the report are described in trying a request on a route.
Deployments
Deployments track the history of API publications. Each deploy of the draft (POST .../apis/{apiId}/deployments), and each write of an API managed as code (by a remote catalog or an outside tool) that changes what is live, adds a deployment record first in the deployments of the API.
| Property | Type | Description |
|---|---|---|
id | string | Unique identifier |
apiRef | string | Reference to the API |
owner | string | Who performed the deployment |
at | number | Timestamp of the deployment |
apiDefinition | object | Snapshot of what was deployed: the routes, backends, flows and documentation of the API, and its plans (their access modes, quotas and plugins decide who gets in and how much) |
version | string | Version of the API at deployment time |
ref | string | The identifier, in the tool that deployed, of the version deployed: a commit sha, a release number, a tag. Kept from the body of POST .../deployments, taken from the deployment_ref metadata of the API for the deploys of a remote catalog. At most 256 characters, null when not given |
deployments[0].ref tells which version of the source is live. The API keeps the last
otoroshi.apis.deployments-history-size deployments (env. OTOROSHI_APIS_DEPLOYMENTS_HISTORY_SIZE, 5 by default). The
full history is the stream of ApiDeploymentEvent sent to the data exporters, each one with the
deploymentId and the ref of its deployment.
APIs managed as code
A tool that holds the desired state of its APIs (a GitOps pipeline, a deployment job of a CI, any declarative tool) writes them as code: it marks each API it manages with its own id in metadata.created_by, external=<tool id>, and every write of such an API through the admin API is a deploy, without any draft. A remote catalog does the same with remote_catalog=<catalog id>.
- The API takes the
stateof the body: it can be created directly inpublished, and its routes are served once the proxy state is synced. - The fields locked in production (
domain,contextPath,routes,backends,flows,documentation,testing) take the content of the body in one write. - The state transitions are the ones of a deploy: a
publishedAPI cannot go back tostaging, and aremovedAPI has to be reopened instagingfirst. - The deployment history and the secret of the testing header stay the ones of the live API, whatever the body holds.
- A write that changes what is live (one of the locked fields, the
plans, or themetadata.deployment_refof the body) adds a deployment owned by the value ofcreated_by, and sends itsApiDeploymentEvent. The same body written again adds none. - Such a write needs the right to write the API, nothing more.
The id of the tool is made of letters, digits, ., _ and -, starts with a letter or a digit, and is at most 128 characters long: another value is refused with 400 invalid_created_by. A remote catalog never takes over an API managed by an outside tool: an API of its source with the id of such an API is refused, and reported in the deploy report, and the undeploy of the catalog leaves it.
{
"id": "my-api",
"state": "published",
"metadata": {
"created_by": "external=my-gitops-tool",
"deployment_ref": "3f9c2e1"
},
...
}
OpenAPI import
Otoroshi can generate an API entity from an OpenAPI specification. When importing from an OpenAPI document:
- The API name, description, and version are extracted from the
infosection - Server URLs are mapped to backend targets
- Each path and method combination is converted to an API route
- Both JSON and YAML formats are supported
Complete API JSON example
{
"id": "api_users_service",
"name": "Users Service",
"description": "API for managing users",
"domain": "api.example.com",
"context_path": "/v1",
"version": "1.0.0",
"versions": ["1.0.0"],
"enabled": true,
"state": "published",
"blueprint": "REST",
"debug_flow": false,
"capture": false,
"export_reporting": false,
"groups": ["default"],
"tags": ["users", "core"],
"metadata": {
"team": "platform"
},
"backends": [
{
"id": "users_backend",
"name": "Users backend",
"backend": {
"targets": [
{
"id": "target_1",
"hostname": "users-service.internal",
"port": 8080,
"tls": false,
"weight": 1
}
],
"root": "/",
"rewrite": false,
"load_balancing": { "type": "RoundRobin" }
},
"client": "default_backend_client"
}
],
"clients_backend_config": [
{
"id": "default_backend_client",
"name": "Default client config",
"client": {
"useCircuitBreaker": true,
"retries": 1,
"callTimeout": 30000,
"globalTimeout": 30000
}
}
],
"flows": [
{
"id": "default_plugin_chain",
"name": "Default flow",
"plugins": [
{
"plugin": "cp:otoroshi.next.plugins.OverrideHost",
"enabled": true,
"include": [],
"exclude": [],
"config": {}
}
]
}
],
"routes": [
{
"id": "route_list_users",
"enabled": true,
"name": "List users",
"frontend": {
"domains": ["oto.tools/users"],
"strip_path": true,
"exact": false,
"headers": {},
"query": {},
"methods": ["GET"]
},
"backend": "users_backend",
"flow_ref": "default_plugin_chain"
},
{
"id": "route_create_user",
"enabled": true,
"name": "Create user",
"frontend": {
"domains": ["oto.tools/users"],
"strip_path": true,
"exact": false,
"headers": {},
"query": {},
"methods": ["POST"]
},
"backend": "users_backend",
"flow_ref": "default_plugin_chain"
}
],
"documentation": {
"enabled": true,
"plans": [
{
"id": "plan_free",
"name": "Free Tier",
"description": "Free access with API key",
"status": "published",
"access_mode_configuration_type": "apikey",
"access_mode_configuration": {
"enabled": true,
"readOnly": false,
"allowClientIdOnly": false,
"tags": [],
"metadata": {}
},
"pricing": {
"id": "pricing_free",
"name": "Free",
"enabled": false,
"price": 0,
"currency": "EUR",
"params": {}
}
}
],
"home": {},
"logo": {},
"references": [],
"resources": [],
"navigation": [],
"redirections": [],
"search": { "enabled": true },
"metadata": {},
"tags": []
},
"clients": [
{
"id": "client_acme",
"name": "ACME Corp",
"description": "ACME Corp developer account",
"tags": [],
"metadata": {}
}
],
"testing": {
"enabled": false,
"headerKey": "X-OTOROSHI-TESTING",
"headerValue": "secret-test-value"
},
"deployments": []
}
Admin API
The API entity can be managed through the admin API:
GET /api/apis # List all APIs
POST /api/apis # Create a new API
GET /api/apis/:id # Get an API by ID
PUT /api/apis/:id # Update an API
DELETE /api/apis/:id # Delete an API
PATCH /api/apis/:id # Partially update an API
A request can be tried on a route of an API:
POST /apis/apis.otoroshi.io/v1/apis/:id/routes/:routeId/_tryit # Try a request on a route of an API
Subscriptions are managed at:
GET /api/api-subscriptions # List all subscriptions
POST /api/api-subscriptions # Create a subscription
GET /api/api-subscriptions/:id # Get a subscription
PUT /api/api-subscriptions/:id # Update a subscription
DELETE /api/api-subscriptions/:id # Delete a subscription
Related entities
- Routes - The route entity that API routes are converted into at runtime
- Backends - Global reusable backends that can be referenced by API backends
- API Keys - Credentials generated when subscribing with
apikeyaccess mode - Certificates - Certificates used with
mtlsaccess mode - JWT Verifiers - Verifiers used with
jwtandoauth2-remoteaccess modes - API consumers and plugin flows - How a plan identifies its callers and how plan plugins are applied