> ## Documentation Index
> Fetch the complete documentation index at: https://docs.instructorphp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Instructor for PHP

InstructorPHP is a modular AI toolkit for PHP 8.3 and later. Use a package on its
own or combine packages according to your application's needs.

## Choose a package

* **[Polyglot](https://docs.instructorphp.com/packages/polyglot/overview.md)** provides LLM inference, embeddings, streaming, and typed decision models through a shared PHP API.
* **[Instructor](https://docs.instructorphp.com/packages/instructor/introduction.md)** extracts validated PHP objects from LLM responses.
* **[Agents](https://docs.instructorphp.com/packages/agents/01-introduction.md)** provides an agent loop with tools, state, and execution controls.
* **[AgentCtrl](https://docs.instructorphp.com/packages/agent-ctrl/1-overview.md)** orchestrates coding-agent CLIs from PHP.

Install the complete toolkit:

```bash theme={null}
composer require cognesy/instructor-php
```

For structured extraction alone, install `cognesy/instructor-struct`. See the
[Instructor quickstart](https://docs.instructorphp.com/packages/instructor/quickstart.md)
for the standalone setup.

## First structured extraction

Set `OPENAI_API_KEY` in your environment, then run:

```php theme={null}
<?php
require __DIR__ . '/vendor/autoload.php';

use Cognesy\Instructor\StructuredOutput;

class Person {
    public string $name;
    public int $age;
}

$person = StructuredOutput::using('openai')
    ->with(
        messages: 'Jason is 28 years old.',
        responseModel: Person::class,
    )
    ->get();

echo $person->name;
echo $person->age;
```

Credentials and model availability depend on your provider. Keep secrets outside
source code and check the documentation for the version installed by Composer.

## Documentation and community

* [Canonical documentation](https://docs.instructorphp.com/index.md): Package guides and API usage.
* [Agent starting guide](https://instructorphp.com/llms.txt): A concise guide to useful Markdown pages.
* [Complete Markdown catalog](https://instructorphp.com/llms-index.txt): All generated documentation links.
* [Articles](https://instructorphp.com/articles): Tutorials and implementation guidance.
* [GitHub](https://github.com/cognesy/instructor-php): Source, issues, discussions, and releases.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.