README.md•4.56 kB
# GPT-5 Query Tool for Claude
This tool allows Claude to query OpenAI's GPT-5 models with arbitrary context, including file contents.
## Setup
1. Install dependencies (already in requirements.txt):
```bash
pip install requests python-dotenv
```
2. Set your OpenAI API key:
```bash
export OPENAI_API_KEY="your-api-key-here"
```
Or create a `.env` file in the project root:
```
OPENAI_API_KEY=your-api-key-here
```
3. Make the script executable:
```bash
chmod +x tools/query_gpt5.py
```
## Usage
### Basic Query
```bash
python tools/query_gpt5.py --query "What is the capital of France?"
```
### Query with File Context
Include one or more files as context for the query:
```bash
python tools/query_gpt5.py \
--query "Explain what this code does and suggest improvements" \
--files server.py config.py
```
### Advanced Options
#### Choose a Model
Available models: `gpt-5`, `gpt-5-mini`, `gpt-5-nano`
```bash
python tools/query_gpt5.py \
--query "Your question" \
--model gpt-5-mini
```
#### Adjust Reasoning Effort
Control how much the model "thinks" before responding. Options: `minimal`, `low`, `medium`, `high`
```bash
python tools/query_gpt5.py \
--query "Solve this complex algorithmic problem" \
--reasoning-effort high
```
#### Set Maximum Tokens
```bash
python tools/query_gpt5.py \
--query "Your question" \
--max-tokens 8000
```
### Complete Example
```bash
python tools/query_gpt5.py \
-q "Review this code for potential bugs and security issues" \
-f app.py utils.py database.py \
-m gpt-5 \
-r high \
-t 4096
```
## Command-Line Options
| Short | Long | Description | Default |
|-------|------|-------------|---------|
| `-q` | `--query` | Question or prompt (required) | - |
| `-f` | `--files` | File paths to include as context | None |
| `-m` | `--model` | Model: gpt-5, gpt-5-mini, gpt-5-nano | gpt-5 |
| `-r` | `--reasoning-effort` | Reasoning level: minimal, low, medium, high | medium |
| `-t` | `--max-tokens` | Maximum completion tokens | 4096 |
| `-h` | `--help` | Show help message | - |
## Model Comparison
### GPT-5
- Most capable model
- Best for complex reasoning and coding tasks
- Pricing: $1.25/1M input tokens, $10/1M output tokens
### GPT-5-mini
- Faster and more cost-effective
- Good for most tasks
- Lower pricing than GPT-5
### GPT-5-nano
- Fastest and cheapest
- Good for simple queries
- Lowest pricing
## Reasoning Effort Levels
- **minimal**: Fast responses for simple queries
- **low**: Basic reasoning
- **medium**: Balanced (default)
- **high**: Deep reasoning for complex problems (note: this uses more tokens as reasoning tokens count as output)
## Use Cases
### Code Review
```bash
python tools/query_gpt5.py \
-q "Review this code for bugs, performance issues, and best practices" \
-f src/server.py src/routes.py \
-r high
```
### Architecture Advice
```bash
python tools/query_gpt5.py \
-q "Based on these files, suggest improvements to the architecture" \
-f src/server.py src/database.py src/config.py
```
### Bug Analysis
```bash
python tools/query_gpt5.py \
-q "I'm getting an error in authentication. Can you help debug?" \
-f src/auth.py src/middleware.py
```
### Documentation Generation
```bash
python tools/query_gpt5.py \
-q "Generate comprehensive API documentation for these files" \
-f src/api.py src/models.py
```
### Code Comparison
```bash
python tools/query_gpt5.py \
-q "Compare these two implementations and recommend which is better" \
-f implementation_a.py implementation_b.py
```
## Tips
1. **File Context**: Include relevant files to get better, context-aware answers
2. **Reasoning Effort**: Use `high` for complex problems, `minimal` for simple queries to save tokens
3. **Model Selection**: Start with `gpt-5-mini` for cost-effectiveness, upgrade to `gpt-5` if needed
4. **Token Limits**: GPT-5 supports up to 272K input tokens + 128K output tokens (400K total)
5. **API Key**: Keep your API key secure, never commit it to version control
## Troubleshooting
### "Error: OPENAI_API_KEY environment variable is required"
Set your API key:
```bash
export OPENAI_API_KEY="your-key"
```
### "Could not read file"
Check that file paths are correct and you have read permissions
### API Errors
- Check your API key is valid
- Ensure you have sufficient credits
- Verify the model name is correct
## Notes
- GPT-5-pro is currently only available via ChatGPT's $200/month tier, not the API
- This tool uses the standard GPT-5 models available via the API
- Reasoning tokens count as output tokens in pricing