Skip to main content
Polyglot resolves two configuration types — one for inference and one for embeddings. Both follow the same patterns: they can be loaded from YAML presets, constructed from arrays, or parsed from DSN strings.

LLMConfig

LLMConfig holds all the settings needed to connect to an inference provider and select a model. Namespace: Cognesy\Polyglot\Inference\Config\LLMConfig

Fields

Creating a Config

There are three ways to create an LLMConfig:

Presets

Presets are YAML files that live in well-known directories. Polyglot searches these paths in order:
  1. config/llm/presets/ (project root)
  2. packages/polyglot/resources/config/llm/presets/ (monorepo)
  3. vendor/cognesy/instructor-php/packages/polyglot/resources/config/llm/presets/
  4. vendor/cognesy/instructor-polyglot/resources/config/llm/presets/
You may also pass a custom base path:

Overriding Values

Use withOverrides() 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 expect int 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

Creating a Config

Presets for embeddings are resolved from similar paths, under the embed config group:
  1. config/embed/presets/
  2. packages/polyglot/resources/config/embed/presets/
  3. vendor/cognesy/instructor-php/packages/polyglot/resources/config/embed/presets/
  4. vendor/cognesy/instructor-polyglot/resources/config/embed/presets/

Overriding Values

For EmbeddingsConfig, type coercion applies to the dimensions and maxInputs fields.
Note: The legacy field name defaultDimensions is automatically normalized to dimensions during config loading.

Retry Policies

Retry behavior is configured separately from the provider config, via dedicated policy objects. Retry policies must not be placed inside the options array — Polyglot will throw an InvalidArgumentException if you attempt this.

InferenceRetryPolicy

The InferenceRetryPolicy provides fine-grained control over retry behavior for inference requests:
The retry delay uses exponential backoff: 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
Length recovery allows automatic continuation when a response is cut short by the provider’s token limit. Two strategies are available: '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, use EmbeddingsRetryPolicy: