Skip to main content
OpenAI is the default and recommended LLM provider for Graphiti, offering state-of-the-art language models with structured output support.

Installation

OpenAI support is included in the base installation:

Configuration

Environment Variables

.env
Graphiti automatically detects and uses the OPENAI_API_KEY environment variable.

Basic Setup

By default, Graphiti uses OpenAI with no additional configuration:

Custom LLM Configuration

Customize the OpenAI LLM client:

Embeddings Configuration

Customize the OpenAI embeddings:

Supported Models

Language Models

  • gpt-4.1-mini (recommended): Latest mini model with great performance
  • gpt-4.1: Full GPT-4.1 model for complex tasks
  • gpt-5-mini: Reasoning model with extended thinking
  • gpt-5: Advanced reasoning model
  • o1, o3: Specialized reasoning models

Embedding Models

  • text-embedding-3-small (default): 1536 dimensions, cost-effective
  • text-embedding-3-large: 3072 dimensions, highest quality
  • text-embedding-ada-002: Legacy model, 1536 dimensions

LLM Configuration Options

Embedder Configuration Options

Structured Output Support

OpenAI models support native structured outputs via the Responses API:
Benefits:
  • Guaranteed valid JSON responses
  • Type-safe Pydantic model outputs
  • Reduced parsing errors and retries

Reasoning Models

For GPT-5, o1, and o3 models, Graphiti automatically handles:
  • Temperature: Disabled (not supported by reasoning models)
  • Max Tokens: Adjusted to model-specific limits
  • Reasoning Effort: Configurable thinking depth
  • Verbosity: Control reasoning output detail

Complete Example

Rate Limiting

Graphiti defaults to low concurrency to avoid rate limits:
.env
If you encounter 429 errors, reduce the concurrency limit.

Error Handling

Graphiti automatically handles:
  • Rate Limit Errors: Exponential backoff and retry
  • Validation Errors: Automatic retry with error context
  • Refusal Errors: Content policy violations (no retry)
  • Timeout Errors: Network and API timeouts

Cost Optimization

  • Use Mini Models: gpt-4.1-mini for most tasks
  • Batch Operations: Process multiple items together
  • Cache Results: Enable caching for repeated queries
  • Token Limits: Adjust max_tokens based on needs