> ## 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.

# Expressions & Variables

> Using built-in variables and simple expressions.

The ONR DSL is intentionally declarative, meaning there is no Turing-complete scripting language embedded. However, you can use built-in variables to dynamically construct paths, headers, and keys.

## Expression Contexts

In positions where the DSL requires an `<expr>`, you can use:

1. **String Literal**: `"abc"`
2. **Variable**: `$channel.key`
3. **Function**: `concat("Bearer ", $channel.key)`

> *Note:* Variables are only evaluated when used as bare expressions. If you wrap them in double quotes (e.g., `"$channel.key"`), they are treated as plain string literals and will *not* be expanded.

## Built-in Variables

These variables are populated at runtime dynamically for every request.

### `channel.*` context

* `$channel.base_url`: The channel base URL (string). Overrides `upstream_config.base_url` if set by the API caller.
* `$channel.key`: The downstream API key/token (string) meant to be passed to the upstream provider.
* `$channel.location`: The provider location or region attached to the selected upstream key, such as `global` or `us-central1`.

### `credential.*` context

* `$credential.project_id`: The project id parsed from the active credential. For Google service account files, this is the JSON `project_id`.

### `request.*` context

* `$request.model`: The original requested model name from the upstream JSON body.
* `$request.model_mapped`: The transformed model name, determined after any `model_map` operations fire.

## Expression Examples

```nginx theme={null}
request {
  # Set a custom header based on the target mapped model
  set_header "x-upstream-model" $request.model_mapped;
}

upstream {
  # Dynamically construct the path
  set_path concat("/v1/", $request.model_mapped, "/chat/completions");
  
  # Inject query strings dynamically
  set_query key $channel.key;
}

provider "vertex" {
  match api = "gemini.generateContent" {
    upstream {
      set_path template("/v1/projects/${credential.project_id}/locations/${channel.location}/publishers/google/models/${request.model_mapped}:generateContent");
    }
  }
}
```
