ReqCassette.Template.Presets (ReqCassette v0.5.1)

View Source

Built-in pattern presets for common API providers.

Presets provide pre-configured regex patterns for dynamic values commonly found in specific API responses. This is especially useful for LLM APIs where message IDs, tool use IDs, and request IDs change with every call.

Available Presets

  • :anthropic - Anthropic Claude API patterns (msg_*, toolu_*, req_*)
  • :openai - OpenAI API patterns (chatcmpl-*, call_*)
  • :llm - All LLM provider patterns combined
  • :common - Common patterns (UUIDs, ISO timestamps)

Usage

Presets can be used alone or combined with custom patterns:

# Use preset only
template: [preset: :anthropic]

# Preset with additional patterns (explicit patterns override preset)
template: [preset: :anthropic, patterns: [order_id: ~r/ORD-\d+/]]

# Combined LLM preset for multi-provider support
template: [preset: :llm]

Pattern Details

Anthropic Patterns

PatternRegexExample
msg_idmsg_[a-zA-Z0-9]+msg_01XzW7o3s58J6KauMpLBFtEf
toolu_idtoolu_[a-zA-Z0-9]+toolu_01K6u2Q9D6W7heeVvKAcLcAJ
anthropic_request_idreq_[a-zA-Z0-9]+req_01234abcdef

OpenAI Patterns

PatternRegexExample
chatcmpl_idchatcmpl-[a-zA-Z0-9]+chatcmpl-abc123def456
call_idcall_[a-zA-Z0-9]+call_abc123

Common Patterns

PatternRegexExample
uuidUUID v4 format550e8400-e29b-41d4-a716-446655440000
iso_timestampISO 8601 datetime2025-01-15T10:30:00Z

Summary

Functions

Lists all available preset names.

Returns patterns for the given preset name.

Returns patterns for the given preset name, raising on error.

Functions

available()

@spec available() :: [atom()]

Lists all available preset names.

Examples

iex> ReqCassette.Template.Presets.available()
[:anthropic, :openai, :llm, :common]

get(name)

@spec get(atom()) :: {:ok, keyword(Regex.t())} | {:error, {:unknown_preset, atom()}}

Returns patterns for the given preset name.

Parameters

  • preset_name - One of :anthropic, :openai, :llm, or :common

Returns

  • {:ok, patterns} - A keyword list of {name, regex} pairs
  • {:error, {:unknown_preset, name}} - If the preset is not recognized

Examples

iex> {:ok, patterns} = ReqCassette.Template.Presets.get(:anthropic)
iex> Keyword.keys(patterns)
[:msg_id, :toolu_id, :anthropic_request_id]

iex> ReqCassette.Template.Presets.get(:unknown)
{:error, {:unknown_preset, :unknown}}

get!(preset_name)

@spec get!(atom()) :: keyword(Regex.t())

Returns patterns for the given preset name, raising on error.

Parameters

  • preset_name - One of :anthropic, :openai, :llm, or :common

Returns

A keyword list of {name, regex} pairs.

Raises

ArgumentError if the preset is not recognized.

Examples

iex> patterns = ReqCassette.Template.Presets.get!(:anthropic)
iex> Keyword.keys(patterns)
[:msg_id, :toolu_id, :anthropic_request_id]