# Patterns

Patterns help recover short, structured alphanumeric tokens — order codes, reference numbers, licence plates — that are easy to mishear when spoken letter-by-letter and digit-by-digit. When you know the shape of a token that may appear in the audio, describe it with a subset of regular-expression syntax and the transcription is corrected to fit.

Patterns are available on the [Realtime](realtime.md), [Prerecorded](prerecorded.md), and [Turns](turns.md) APIs.

## Using Patterns

Pass the `patterns` query parameter as a comma-separated list of patterns. Each one describes a single token to recover.

```
?patterns=AMZ[0-9]{6}
?patterns=[A-Z]{2}[0-9]{2} [A-Z]{3}
?patterns=(INV)?[0-9]{4,5}
?patterns=AMZ[0-9]{6},ORD[0-9]{5}
```

Patterns use a subset of regular-expression syntax:

| Syntax        | Meaning                                              | Example        |
|---------------|------------------------------------------------------|----------------|
| `[0-9]`       | a digit                                              | `[0-9]{6}`     |
| `[A-Z]`       | a letter                                             | `[A-Z]{3}`     |
| `{n}`         | repeat the preceding class exactly `n` times         | `[0-9]{6}`     |
| `{m,n}`       | repeat the preceding class `m` to `n` times          | `[0-9]{4,6}`   |
| `(...)?`      | an optional group — matched only when spoken         | `(INV)?[0-9]{5}` |
| `AMZ`         | literal letters/digits, e.g. a fixed prefix          | `AMZ[0-9]{6}`  |
| ` ` or `-`    | a separator                                          | `[A-Z]{2} [0-9]{3}` |

Optional groups and ranges are resolved against the audio: an optional prefix is added only when it is actually spoken, and a `{m,n}` range adopts the spoken length. The more specific the pattern, the better — a fixed prefix or known structure (`AMZ[0-9]{6}`) is recovered more reliably than an open one.

A pattern matches tokens of at most 32 characters once fully expanded (the prefix and any digits or letters combined); a longer range or repeat is clamped to this limit. This is well above the length of typical order codes and reference numbers.

## Examples

| Token type        | Example value | Pattern                     |
|-------------------|---------------|-----------------------------|
| Order code        | `AMZ374019`   | `AMZ[0-9]{6}`               |
| Reference number  | `4429105538`  | `[0-9]{10}`                 |
| Licence plate     | `RU77 TVG`    | `[A-Z]{2}[0-9]{2} [A-Z]{3}` |
| Invoice (optional prefix) | `INV4821` or `4821` | `(INV)?[0-9]{4}`    |
| Variable-length code | `AMZ3740` … `AMZ374019` | `AMZ[0-9]{4,6}`     |

!!! warning "Only set patterns you expect"
    Patterns improve accuracy on audio that contains the token, but can **degrade** transcription of audio that does not. Set `patterns` only when the expected token is likely present in the request — don't apply them globally.

See the API reference for [Realtime](../../api/speech-to-text/realtime.md), [Prerecorded](../../api/speech-to-text/prerecorded.md), and [Turns](../../api/speech-to-text/turns.md).
