Installation
OpenAI support is included in the base installation:Configuration
Environment Variables
.env
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
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | From env | OpenAI API key |
model | str | "gpt-4.1-mini" | Primary LLM model |
small_model | str | "gpt-4.1-mini" | Model for simpler tasks |
temperature | float | 0.7 | Sampling temperature (0-2) |
max_tokens | int | 8192 | Maximum tokens to generate |
base_url | str | None | Custom API endpoint (for proxies) |
Embedder Configuration Options
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | From env | OpenAI API key |
embedding_model | str | "text-embedding-3-small" | Embedding model |
embedding_dim | int | 1536 | Embedding dimensions |
base_url | str | None | Custom API endpoint |
Structured Output Support
OpenAI models support native structured outputs via the Responses API:- 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
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-minifor most tasks - Batch Operations: Process multiple items together
- Cache Results: Enable caching for repeated queries
- Token Limits: Adjust
max_tokensbased on needs