options array is the escape hatch for provider-specific request fields that fall
outside Polyglot’s unified API. Anything you place in options is passed through to
the underlying provider driver.
Note: Except formax_tokensandstream, all option keys are provider-specific and may not be available or behave identically across providers. Always consult the provider’s API documentation for details.
Setting Options
Pass options throughwithOptions() or the options parameter on with():
withOptions() multiple times will merge the
new keys into the existing set rather than replacing it.
Common Options
These options are widely supported across most providers:Dedicated Helpers Over Raw Options
For common behaviors, prefer the dedicated fluent helpers instead of manually placing values in theoptions array. The helpers ensure correct handling across all providers:
| Instead of this… | Use this… |
|---|---|
withOptions(['stream' => true]) | withStreaming(true) |
withOptions(['max_tokens' => 256]) | withMaxTokens(256) |
withOptions(['retryPolicy' => [...]]) | withRetryPolicy($policy) |
Provider-Specific Options
Different providers accept different option keys. Here are a few examples:OpenAI
Anthropic
Retry Policy
Retry behavior is configured explicitly throughwithRetryPolicy() — never place it
inside the options array. Polyglot will throw an InvalidArgumentException if you do.
| Parameter | Default | Description |
|---|---|---|
maxAttempts | 1 | Total attempts (1 = no retry) |
baseDelayMs | 250 | Base delay in milliseconds |
maxDelayMs | 8000 | Maximum delay cap |
jitter | 'full' | Jitter strategy: none, full, or equal |
retryOnStatus | [408,429,500,...] | HTTP status codes that trigger a retry |
retryOnExceptions | Timeout, Network | Exception classes that trigger a retry |
lengthRecovery | 'none' | Recovery mode: none, continue, increase_max_tokens |
lengthMaxAttempts | 1 | Max attempts for length recovery |
lengthContinuePrompt | 'Continue.' | Prompt used for continue recovery mode |
maxTokensIncrement | 512 | Token increment for increase_max_tokens mode |
Response Cache Policy
Control whether responses are cached in memory for reuse:ResponseCachePolicy::None— no caching (default)ResponseCachePolicy::Memory— cache responses in memory for the current process
Cached Context
UsewithCachedContext() to attach stable, reusable context that should be prepended
to every request. This is useful when you have shared system instructions, tool
definitions, or response formats that remain constant across multiple calls: