> ## 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.

# Environment

## Overview

Environment variables are used at provider configuration time, not in the
structured-output API itself. Your application or preset loader reads the
variables, `LLMConfig` resolves provider settings from them, and
`StructuredOutputRuntime` uses the resulting configuration object.

This keeps the package independent from any specific framework bootstrap process.

## LLM Provider API Keys

Instructor supports many LLM providers. Configure the API keys for the ones you
plan to use in your `.env` file:

```ini theme={null}
# Primary providers
OPENAI_API_KEY=''
ANTHROPIC_API_KEY=''
GEMINI_API_KEY=''

# Additional providers
A21_API_KEY=''
ANYSCALE_API_KEY=''
AZURE_OPENAI_API_KEY=''
CEREBRAS_API_KEY=''
COHERE_API_KEY=''
FIREWORKS_API_KEY=''
GROQ_API_KEY=''
MISTRAL_API_KEY=''
OLLAMA_API_KEY=''
OPENROUTER_API_KEY=''
SAMBANOVA_API_KEY=''
TOGETHER_API_KEY=''
XAI_API_KEY=''
# @doctest id="10f7"
```

Only configure the providers you plan to use. Empty keys are ignored.

## Embedding Provider Keys

If you use embedding features (via companion packages), configure these as well:

```ini theme={null}
AZURE_OPENAI_EMBED_API_KEY=''
JINA_API_KEY=''
# @doctest id="12a9"
```

## Web Service Keys

Scraping and web-related add-ons use their own API keys:

```ini theme={null}
JINAREADER_API_KEY=''
SCRAPFLY_API_KEY=''
SCRAPINGBEE_API_KEY=''
# @doctest id="0b7d"
```

These are not required for core structured-output functionality.

## Configuration Directory Path

The `INSTRUCTOR_CONFIG_PATHS` variable tells the InstructorPHP ecosystem where to
find configuration files:

```ini theme={null}
INSTRUCTOR_CONFIG_PATHS='config,vendor/cognesy/instructor-php/config'
# @doctest id="a56f"
```

This is primarily used by the CLI tooling and companion packages. The
structured-output package resolves provider presets through `LLMConfig::fromPreset()`,
which has its own path resolution logic (see [Configuration Path](configuration_path)).

## How It Fits Together

```
.env file
    |
    v
LLM provider preset (YAML)  <-- reads API key from env
    |
    v
LLMConfig                   <-- typed configuration object
    |
    v
StructuredOutputRuntime      <-- assembled runtime
    |
    v
StructuredOutput             <-- your application code
// @doctest id="0594"
```

The structured-output package never reads environment variables directly. The
separation ensures that the same `LLMConfig` can be constructed from environment
variables, hardcoded values, a framework service container, or any other source.

> **Security:** Keep your `.env` file secure and never commit it to version control.
> For production, use your platform's secrets management system.
