Skip to main content
Instructor provides several levels of configuration for controlling which model is used and how requests are sent to the LLM provider.

Per-Request Options

The simplest way to control the model and options is to pass them directly in the request. This is ideal for one-off adjustments.
You can also use the fluent API for the same result.
The options array is passed directly to the LLM provider. Common options include temperature, max_tokens, and top_p, though available options vary by provider and model.

Using LLMConfig

When you need consistent settings across multiple requests — such as a custom API key, base URL, or organization — use LLMConfig to construct a configured StructuredOutput instance.
Per-request model and options values override the corresponding LLMConfig defaults, so you can set sensible defaults in the config and adjust individual requests as needed.

Using Presets

If you have named LLM configurations defined in a configuration file, you can load them by name.
The preset name is resolved through LLMConfig::fromPreset(), which loads the connection details from your configuration.

Using StructuredOutputRuntime

For the highest level of control, create a StructuredOutputRuntime directly. This gives you access to output mode, retry settings, custom validators, transformers, deserializers, and extractors.

Common Options

These options are widely supported across providers, though exact behavior may vary. Provider-specific options (such as response_format for OpenAI or thinking for Anthropic) can also be passed through the options array. Consult your provider’s API documentation for details.