LLMConfig
LLMConfig holds all the settings needed to connect to an inference provider and select a model.
Namespace: Cognesy\Polyglot\Inference\Config\LLMConfig
Fields
| Field | Type | Default | Description |
|---|---|---|---|
apiUrl | string | '' | Base URL for the provider API |
apiKey | string | '' | Authentication key (marked as #[SensitiveParameter]) |
endpoint | string | '' | API endpoint path (e.g. /chat/completions) |
queryParams | array | [] | Query parameters appended to the URL |
metadata | array | [] | Provider-specific metadata (e.g. organization, project for OpenAI) |
model | string | '' | Model identifier |
maxTokens | int | 1024 | Default max tokens for responses |
contextLength | int | 8000 | Model context window size |
maxOutputLength | int | 4096 | Maximum output length |
driver | string | 'openai-compatible' | Driver name (e.g. openai, anthropic, gemini) |
options | array | [] | Additional provider-specific options |
pricing | array | [] | Token pricing per 1M tokens (input, output, etc.) |
Creating a Config
There are three ways to create anLLMConfig:
Presets
Presets are YAML files that live in well-known directories. Polyglot searches these paths in order:config/llm/presets/(project root)packages/polyglot/resources/config/llm/presets/(monorepo)vendor/cognesy/instructor-php/packages/polyglot/resources/config/llm/presets/vendor/cognesy/instructor-polyglot/resources/config/llm/presets/
Overriding Values
UsewithOverrides() to create a modified copy of an existing config:
Pricing
When pricing data is included in the config, it can be used with a cost calculator to compute costs externally. Pricing values are specified in USD per 1 million tokens:Type Coercion
Both config classes automatically coerce numeric string values to integers for fields that expectint types. This is useful when loading values from YAML files or environment variables where values may arrive as strings. For LLMConfig, the coerced fields are maxTokens, contextLength, and maxOutputLength.
EmbeddingsConfig
EmbeddingsConfig holds the settings for connecting to an embeddings provider.
Namespace: Cognesy\Polyglot\Embeddings\Config\EmbeddingsConfig
Fields
| Field | Type | Default | Description |
|---|---|---|---|
apiUrl | string | '' | Base URL for the provider API |
apiKey | string | '' | Authentication key |
endpoint | string | '' | API endpoint path |
model | string | '' | Model identifier |
dimensions | int | 0 | Embedding dimensions (0 = provider default) |
maxInputs | int | 0 | Maximum number of inputs per request |
metadata | array | [] | Provider-specific metadata |
driver | string | 'openai' | Driver name |
Creating a Config
embed config group:
config/embed/presets/packages/polyglot/resources/config/embed/presets/vendor/cognesy/instructor-php/packages/polyglot/resources/config/embed/presets/vendor/cognesy/instructor-polyglot/resources/config/embed/presets/
Overriding Values
EmbeddingsConfig, type coercion applies to the dimensions and maxInputs fields.
Note: The legacy field namedefaultDimensionsis automatically normalized todimensionsduring config loading.
Retry Policies
Retry behavior is configured separately from the provider config, via dedicated policy objects. Retry policies must not be placed inside theoptions array — Polyglot will throw an InvalidArgumentException if you attempt this.
InferenceRetryPolicy
TheInferenceRetryPolicy provides fine-grained control over retry behavior for inference requests:
baseDelayMs * 2^(attempt-1), capped at maxDelayMs. The jitter strategy adds randomness to avoid thundering herd problems:
'none'— exact exponential backoff'full'— random value between 0 and the calculated delay'equal'— half the delay plus a random amount up to half the delay
'continue' appends the partial response and sends a continuation prompt, while 'increase_max_tokens' retries with a higher max_tokens value.
The policy also retries on specific exceptions by default: TimeoutException and NetworkException. Provider-specific errors classified as retriable (rate limits, quota exceeded, transient errors) are also retried automatically.
EmbeddingsRetryPolicy
For embeddings, useEmbeddingsRetryPolicy: