Facades
The package provides four Laravel facades that serve as the primary entry points for interacting with LLMs and code agents. Each facade resolves a fresh instance from the service container, so you can chain methods freely without worrying about shared state between calls.StructuredOutput
The primary facade for extracting structured data from unstructured text. Given a response model class (a plain PHP DTO with typed properties), the facade prompts the LLM, validates the response against the model’s type constraints, and returns a fully typed object.Basic Usage
With System Prompt
A system prompt steers the LLM’s behavior for the extraction task. Use it to provide domain-specific instructions or constraints.With Examples (Few-Shot Learning)
Providing input/output examples helps the LLM understand the expected extraction pattern, especially for ambiguous or domain-specific data.Switching Connections
Each call can target a different LLM provider by specifying a connection name that matches an entry in yourconfig/instructor.php connections array.
Fluent API
All configuration can also be set with individual fluent methods. This is useful when you build requests dynamically.Return Types
By default,get() returns the deserialized object matching your response model. For simpler extractions, convenience methods cast the result to scalar types.
Available Methods
Runtime policy such as retries, output mode, validators, transformers, deserializers, and extractors is configured on
StructuredOutputRuntime and then passed via withRuntime(...).
Inference
For raw LLM inference without structured output extraction. Use this when you need free-form text generation, JSON responses, or tool-calling capabilities without the overhead of schema validation and deserialization.Basic Usage
With System Message
Pass aMessages object when you need fine-grained control over the conversation structure.
JSON Response
Request a JSON-formatted response and parse it directly into a PHP array.Switching Connections
Available Methods
Embeddings
For generating text embeddings (dense vector representations). Embeddings are useful for semantic search, clustering, classification, and similarity comparison.Basic Usage
Switching Connections
With Custom Model
Full Response
Theget() method returns the complete response object, which includes both the embedding vectors and usage statistics.
Available Methods
AgentCtrl
For invoking CLI-based code agents (Claude Code, Codex, OpenCode) that can execute code, modify files, and perform complex multi-step tasks. The facade provides a builder pattern for configuring agent execution and returns a structuredAgentResponse with the generated output, tool calls, token usage, and cost.
Basic Usage
Agent Selection
Configuration
The facade automatically applies Laravel configuration defaults fromconfig/instructor.php for each agent type. Builder methods override those defaults for a single call.
Streaming
Process output in real-time with streaming callbacks. TheonText, onToolUse, and onComplete callbacks fire as the agent generates output.
Response Object
Session Management
Resume previous sessions for multi-turn agent interactions. The session ID from a previous response lets you continue where you left off.Available Methods
Dependency Injection
Instead of facades, you can inject the underlying service classes directly into your constructors or method signatures. Laravel’s service container resolves them with the same configuration and HTTP client bindings that the facades use.- Better testability — you can mock the injected service or use constructor injection with a fake
- Explicit dependencies — the class signature documents exactly which services it needs
- IDE autocompletion — your editor can provide method suggestions on the typed property
Facade Behavior
All facades proxy to the underlying service classes registered in the container. TheStructuredOutput facade is registered as a non-singleton (bind), so each resolution returns a fresh instance. Inference and Embeddings are registered as singletons. This means you can chain methods on any facade call without side effects: