---
title: "Create a fee rule"
method: POST
path: "/v1/contexts/{contextId}/fee-rules"
tags: ["Configuration Fee Rules"]
---

# Create a fee rule

`POST /v1/contexts/{contextId}/fee-rules`

Use this endpoint to create a new fee rule that maps transaction metadata to a fee schedule within a context.

Priority must be unique within a context across all sides (LEFT, RIGHT, and ANY rules share the same priority space). The caller must also be allowed to read the referenced fee schedule.

## Path parameters

- `contextId` string, uuid, required

## Headers

- `X-Request-Id` string
- `X-Idempotency-Key` string

## Request body

- CreateFeeRuleRequest — Request payload for creating a fee rule
  - `feeScheduleId` string, required — The fee schedule to apply when this rule matches
  - `name` string, required — Display name for the fee rule
  - `side` 'LEFT' | 'RIGHT' | 'ANY', required — Which transaction side this rule applies to
  - `priority` integer — Evaluation priority (must be unique within the context; LEFT, RIGHT, and ANY rules share the same priority space)
  - `predicates` FieldPredicateRequest[] — Conditions that must all match for this rule to apply
    - `field` string, required — Transaction field to evaluate
    - `operator` 'EQUALS' | 'IN' | 'EXISTS', required — Comparison operator
    - `value` string — Single value to compare against (used with EQUALS and EXISTS operators)
    - `values` string[] — List of values to compare against (used with IN operator)

## Response `201`

Successfully created fee rule.

The response includes the `X-Idempotency-Replayed` header.

If the value is false, the request was just processed. If the value is true, the response is a replay of a previously processed request.

See [Retries and idempotency](/en/reference/retries-idempotency) for more details.

- FeeRuleResponse — A fee rule that maps transaction metadata to a fee schedule within a reconciliation context
  - `id` string, uuid — Unique identifier for the fee rule
  - `contextId` string, uuid — Reconciliation context this rule belongs to
  - `feeScheduleId` string, uuid — Fee schedule applied when this rule matches
  - `name` string — Display name for the fee rule
  - `side` 'LEFT' | 'RIGHT' | 'ANY' — Which transaction side this rule applies to
  - `priority` integer — Evaluation priority (lower numbers are evaluated first; LEFT, RIGHT, and ANY rules share the same priority space)
  - `predicates` FieldPredicateResponse[] — Conditions that must all match for this rule to apply
    - `field` string — Transaction field being evaluated
    - `operator` 'EQUALS' | 'IN' | 'EXISTS' — Comparison operator
    - `value` string — Single value being compared
    - `values` string[] — List of values being compared
  - `createdAt` string, date-time — Creation timestamp in RFC 3339 format
  - `updatedAt` string, date-time — Last update timestamp in RFC 3339 format

## Other responses

- `400` — Invalid request payload
- `401` — The request lacks valid authentication credentials.
- `403` — You do not have permission to access this resource.
- `404` — Context not found
- `409` — Conflict — duplicate priority or name within this context
- `500` — An unexpected error occurred on the server.

---

[API](https://skmtc.net/lerian/apis/identity-plugin.md) · [All operations](https://skmtc.net/lerian/apis/identity-plugin/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/lerian/identity-plugin/versions/25daba385532/schema)
