> ## Documentation Index
> Fetch the complete documentation index at: https://onr.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Request Block

> Mutating logic for inflight headers and JSON bodies.

The `request` block enables you to perform lightweight transformations on the payload *before* it gets sent to the upstream provider.

## Header Operations

You can arbitrarily set, delete, or filter HTTP headers going to the upstream server.

```nginx theme={null}
request {
  set_header "x-trace-id" "trace-123";
  set_header "x-foo" concat("a-", $request.model_mapped);
  
  del_header "x-remove-me";

  # Remove specific values from a header (denylist)
  filter_header_values "anthropic-beta" "context-1m-*";

  # Keep only specific values in a header (allowlist)
  keep_header_values "anthropic-beta" "computer-use-*" "context-management-*";
}
```

*Note: If the same header is set multiple times, the last one wins. Deletions and filter/keep operations apply in order.*

### filter\_header\_values

Removes header value items that match any of the given patterns (denylist). Non-matching items are kept.

```nginx theme={null}
request {
  filter_header_values "anthropic-beta" "context-1m-*" "fast-mode-*";
  filter_header_values "x-feature-flags" "exp-*" "debug" separator=";";
}
```

* Syntax: `filter_header_values <header> <pattern>... [separator="<sep>"];`
* Default separator is `,`. Output is normalized (`", "` for comma, `"<sep> "` for others).
* Pattern matching supports `*` wildcards; case-insensitive is not applied (patterns must match the exact case used by the client).
* If all values are removed, the header is deleted.

### keep\_header\_values

Keeps only header value items that match any of the given patterns (allowlist). Non-matching items are removed.

```nginx theme={null}
request {
  keep_header_values "anthropic-beta" "computer-use-*" "context-management-*";
  keep_header_values "x-feature-flags" "stable-*" separator=";";
}
```

* Syntax: `keep_header_values <header> <pattern>... [separator="<sep>"];`
* Mirror of `filter_header_values` with inverted logic: patterns select what to **keep**.
* Same separator and output formatting rules as `filter_header_values`.
* If no values match, the header is deleted.

## Model Mapping

Use `model_map` to alias or hardcode model names conditionally.

```nginx theme={null}
request {
  model_map "gpt-4o-mini" "gpt4o-mini-prod";
  model_map "gpt-4o-mini" $request.model;
  
  model_map_default $request.model;
}
```

* Maps `$request.model` to `$request.model_mapped`.
* Exact match on the `from` string.
* If no matches occur, `model_map_default` dictates what `$request.model_mapped` becomes.

## JSON Mutations

Apply lightweight mutations directly to the upstream JSON body.

```nginx theme={null}
request {
  json_set "$.stream" true;
  json_set_if_absent "$.instructions" "";
  
  json_rename "$.max_tokens" "$.max_completion_tokens";
  json_wrap_input_text "$.input";
  json_del "$.tools";

  # Populate a JSON array from a downstream request header, then filter it
  json_set_header_values "$.anthropic_beta" "anthropic-beta";
  json_keep_values "$.anthropic_beta" "computer-use-*" "context-management-*";
  json_filter_values "$.anthropic_beta" "context-1m-*";
}
```

* Supports a subset of object-path JSONPath expressions (e.g. `$.a.b.c`).
* `json_set` values support primitives (`true`, `false`, `null`, integers, strings) or expressions (like `concat(...)`).
* `json_wrap_input_text` converts a string field into an OpenAI Responses `input` message list, leaves missing or already-array values unchanged, and rejects other types.
* `json_keep_values` filters a JSON string array, **keeping only** values that match any pattern (allowlist). Use after `json_set_header_values` to restrict a header-sourced array to a known-safe set.
* `json_filter_values` filters a JSON string array, **removing** values that match any pattern (denylist).
* Both `json_keep_values` and `json_filter_values` support `*` wildcards, are case-insensitive, and delete the field if no values remain.

## Structural Request Mapping

Use `req_map` to apply heavy, cross-provider schema transformations (such as converting an OpenAI JSON request into a Gemini or Anthropic JSON request).

```nginx theme={null}
request { req_map <mode>; }
```

Use `after_req_map` when a request JSON mutation must run after the structural mapping step.

```nginx theme={null}
request {
  req_map openai_chat_to_anthropic_messages;

  after_req_map {
    json_set "$.anthropic_version" "bedrock-2023-05-31";
    json_del_if_missing "$.tool_choice" "$.tools";
  }
}
```

* Only request JSON mutation directives are allowed inside `after_req_map`.
* If no `req_map` is configured, `after_req_map` runs after the normal request JSON operations.

### Built-in Modes (v0.1)

* `openai_chat_to_openai_responses`
* `anthropic_to_openai_chat`
* `gemini_to_openai_chat`
* `openai_chat_to_gemini_generate_content`
* `openai_chat_to_anthropic_messages`
