Overview
Full Instructor setup consists of following steps:- Step 1: Install Instructor via Composer
- Step 2: Publish Instructor assets (configurations and prompts) to your project directory
- Step 3: Set up LLM provider API key(s) in your .env file
- Step 4: Set configuration location in your .env file (optional)
Step 1: Install Instructor via Composer
You can install Instructor via Composer by running:Step 2: Publish Instructor Files to Your Project
Instructor comes with a set of configuration files and prompt templates that you can publish to your project directory. This will allow you to customize the library’s behavior and use different prompt templates. These files can be found in thevendor/cognesy/instructor-php directory:
.env-dist- Environment variables for API keys and configuration paths/config/*.php- Configurations of Instructor modules/prompts/*- Prompt templates for generating structured data from text
Step 3: Set Up LLM Provider API Key(s)
If you’re using commercial LLM providers like OpenAI, you’ll need to set up API keys in your project’s.env file.
Open the .env file in your project directory and set up API keys for the LLM providers you plan to use. You can find
the keys in the respective provider’s dashboard.
.env-dist for other API keys Instructor uses in its default configuration files.
Step 4: Set Configuration Location (optional)
Instructor uses a configuration directory to store its settings, e.g. LLM provider configurations. You can set the path to this directory viaSettings::setPath('/path/to/config') in your code.
But to make it easier you can just set the value in your .env file. Settings will pick it up automatically
from there. This way you don’t have to set it in every script.
INSTRUCTOR_CONFIG_PATHS is set automatically if you use the Instructor CLI tool to publish assets.Framework Integration
Laravel Projects
For Laravel applications, it’s recommended to align with the framework’s directory structure:- Place configuration files in Laravel’s
configdirectory - Store prompts in Laravel’s
resourcesdirectory - Use Laravel’s default
.envfile location
config/app.php or create a dedicated service provider.
Symfony Projects
For Symfony applications, use the standard Symfony directory structure:- Place configuration in Symfony’s package configuration directory
- Store prompts in Symfony’s
resourcesdirectory - Use Symfony’s default
.envfile location
Custom Framework Location
You can use environment variables to set the location of configuration files:Using CLI Tool
After installing Instructor via Composer, you may want to publish the library’s configuration files and resources to your project, so you can modify them according to your needs. You can do this either manually or automatically using the provided CLI tool.- Copy configuration files from
vendor/cognesy/instructor-php/configtoconfig/instructor/ - Copy prompt templates from
vendor/cognesy/instructor-php/promptstoresources/prompts/ - Merge (or copy)
vendor/cognesy/instructor-php/.env-distfile to.envwith environment variables
Command Options
-c, --target-config-dir=DIR- Custom directory for configuration files (default:config/instructor)-p, --target-prompts-dir=DIR- Custom directory for prompt templates (default:resources/prompts)-e, --target-env-file=FILE- Custom location for .env file (default:.env)-l, --log-file=FILE- Optional log file path to track the publishing process--no-op- Dry run mode - shows what would be copied without making changes
Example Usage
When merging
.env files, the tool will only add missing variables, preserving your existing file content, formatting and comments.