Environment:Spcl Graph of thoughts OpenAI API Access
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, LLM_Reasoning |
| Last Updated | 2026-02-14 03:30 GMT |
Overview
OpenAI API credentials and configuration environment for GPT-3.5-turbo and GPT-4 language model access.
Description
This environment defines the credentials and configuration required to use the ChatGPT language model backend in the Graph of Thoughts framework. It requires a valid OpenAI API key (set as the `OPENAI_API_KEY` environment variable or in `config.json`) and optionally an organization identifier. The ChatGPT class reads its configuration from a JSON file that specifies the model ID, token costs, temperature, max tokens, and stop sequences.
Usage
Use this environment when running any Graph of Thoughts workflow that uses the `ChatGPT` language model backend. This includes all three benchmark examples (sorting, keyword counting, document merging) and any custom GoT workflows using OpenAI models.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| Network | Internet access | Required for OpenAI API calls |
| API Account | OpenAI account with billing | Required to obtain API key |
Dependencies
System Packages
- Internet connectivity (HTTPS to `api.openai.com`)
Python Packages
- `openai` >= 1.0.0, < 2.0.0
- `backoff` >= 2.2.1, < 3.0.0
Configuration Files
- `config.json` — Copy of `config_template.json` with API key and model settings filled in. Must contain a key matching the `model_name` parameter (e.g., `"chatgpt"`, `"chatgpt4"`).
Credentials
The following credentials must be provided:
- `OPENAI_API_KEY`: OpenAI API key. Can be set as an environment variable or in the `api_key` field of `config.json`. Raises ValueError if not set.
- `organization` (optional): OpenAI organization ID in `config.json`. A warning is logged if empty but execution continues.
Quick Install
# Install the framework (includes openai and backoff)
pip install graph_of_thoughts
# Set your API key
export OPENAI_API_KEY="sk-your-key-here"
# Create config.json from template
cp graph_of_thoughts/language_models/config_template.json config.json
# Edit config.json to fill in your api_key and organization
Code Evidence
API key validation from `graph_of_thoughts/language_models/chatgpt.py:57-59`:
self.api_key: str = os.getenv("OPENAI_API_KEY", self.config["api_key"])
if self.api_key == "":
raise ValueError("OPENAI_API_KEY is not set")
Organization warning from `graph_of_thoughts/language_models/chatgpt.py:55-56`:
if self.organization == "":
self.logger.warning("OPENAI_ORGANIZATION is not set")
OpenAI client initialization from `graph_of_thoughts/language_models/chatgpt.py:61`:
self.client = OpenAI(api_key=self.api_key, organization=self.organization)
Config template structure from `config_template.json:2-11`:
"chatgpt" : {
"model_id": "gpt-3.5-turbo",
"prompt_token_cost": 0.0015,
"response_token_cost": 0.002,
"temperature": 1.0,
"max_tokens": 1536,
"stop": null,
"organization": "",
"api_key": ""
}
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `ValueError: OPENAI_API_KEY is not set` | No API key in environment variable or config.json | Set `export OPENAI_API_KEY="sk-..."` or fill the `api_key` field in config.json |
| `WARNING: OPENAI_ORGANIZATION is not set` | Organization field is empty in config.json | Fill the `organization` field in config.json, or ignore if not using org-scoped billing |
| `openai.OpenAIError` (various) | API rate limits, invalid key, or network issues | The ChatGPT class uses `backoff.on_exception` with exponential backoff (max 10s, max 6 tries). Check API key validity and billing status |
| `FileNotFoundError: config.json` | Config file not found at specified path | Copy `config_template.json` to `config.json` and provide the correct path when instantiating ChatGPT |
Compatibility Notes
- Model Selection: The config template includes `chatgpt` (gpt-3.5-turbo) and `chatgpt4` (gpt-4). Custom model IDs can be added following the same JSON structure.
- Token Costs: The `prompt_token_cost` and `response_token_cost` values in the config must be updated to match current OpenAI pricing; the template values may be outdated.
- API Version: The code uses the OpenAI Python SDK v1.0+ (`from openai import OpenAI`), which is incompatible with the older v0.x API.