Skip to content

Conversation

semikolon
Copy link

@semikolon semikolon commented Aug 22, 2025

Context

This PR's resolveEnvVars work follows and complements musistudio/claude-code-router#529 (Environment Variable Interpolation for API Keys), aligning LLMS-side transformations with the router's config interpolation.

GPT-5 Core API Compatibility & Transformer Support

Problem: GPT-5 reasoning parameter compatibility crisis blocking Claude Code interactive mode

Solution: Complete end-to-end fix spanning both repositories:

  • LLMS: Parameter transformation & API compatibility ✅
  • CCR: Intuitive user experience via inline tokens (Part 2)

🔧 Key Fixes

  • Tools Format Validation: Fixed "Missing required parameter" errors by cleaning GPT-5-rejected JSON schema metadata
  • Parameter Mapping: Automatic conversion of max_tokens → max_completion_tokens for GPT-5 models
  • Reasoning Support: Convert reasoning parameters to GPT-5's reasoning_effort format
  • Tool Format Conversion: Seamless Anthropic → OpenAI tool format transformation
  • Response Processing: Extract and transform reasoning content from GPT-5 responses
  • API Format Normalization: Strip extra image fields, convert server_tool_use patterns to proper role:tool messages, ensure strict OpenAI format compliance

🧪 Testing

✅ GPT-5 models now respond without API errors
✅ Tool calling works with complex Anthropic-format tools
✅ Reasoning parameters properly converted and processed
✅ Compatible with Claude Code Router integration
Image & tool message normalization (7 comprehensive test cases)

📋 Related PRs

🔄 Commit Range

This PR represents commits 0c7a2d9 through eb1424e - the core GPT-5 functionality implementation with API format fixes.

🔗 Cross-Repository Impact

This change is required for Claude Code Router's GPT-5 reasoning features to function properly.

Related PRs (complete series)

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

semikolon and others added 10 commits August 13, 2025 09:59
- Add service layer architecture details
- Include build system configuration info
- Add environment configuration guidance
- Document enhanced transformer implementation
- Include code style guidelines and development workflow

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add env-resolver utility with comprehensive error handling
- Resolve $OPENAI_API_KEY and other env vars in provider config
- Add comprehensive test suite with 21 passing tests
- Fix authentication issues where API keys were stored as literal strings
- Add API key redaction for secure logging

This resolves the core authentication problem where llms service
was storing '$OPENAI_API_KEY' literally instead of resolving it
to the actual environment variable value.
Prevent local Claude Code settings from being committed to repository.
These files contain personal development tool preferences that should
remain local to each developer.
- Convert Anthropic tool format to OpenAI function format
- Handle tools parameter transformation for OpenAI Chat Completions API
- Enable GPT-5 compatibility through CCR direct routing
✅ Successfully tested GPT-5 through CCR with tools working
✅ OpenAI transformer converts Anthropic→OpenAI tool formats
✅ Parameter mapping handles max_tokens→max_completion_tokens
✅ Clean architecture using Chat Completions API (not Responses)
✅ Resolved npm caching issues and phantom process problems

- Add comprehensive npm troubleshooting section to CLAUDE.md
- Document the week-long debugging journey and solutions
- GPT-5 now works smoothly in Claude Code via CCR

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Document Chat Completions API vs Responses API performance comparison
- Explain technical architecture and transformation flow
- Add production-ready configuration examples
- Clarify reasoning token support and limitations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add support for reasoning content in JSON responses
- Convert OpenAI reasoning field to Anthropic thinking format
- Handle both streaming and non-streaming GPT-5 reasoning output
- Maintain backward compatibility with existing reasoning logic

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add normalizeImageContent() method to strip extra fields and ensure strict OpenAI format
- Add normalizeToolMessages() method to convert server_tool_use patterns to role:tool messages
- Integrate normalization into existing transformRequestOut() method
- Add comprehensive test suite with 7 test cases covering image and tool normalization
- Fixes GPT-5 API 400 errors while preserving existing tool format conversion functionality

Resolves:
- Invalid parameter: messages[1].content[0]. Expected an object with a type property
- Tool call ID pattern mismatches in server_tool_use → role:tool conversion
semikolon added a commit to semikolon/llms that referenced this pull request Aug 23, 2025
…transformer

✅ COMBINED FUNCTIONALITY:
- GPT-5 parameter transformations (max_tokens → max_completion_tokens)
- Reasoning parameter handling (effort, verbosity validation)
- Tool format conversion with JSON schema cleaning
- CRITICAL: normalizeImageContent() fixes for GPT-5 400 errors
- CRITICAL: normalizeToolMessages() fixes for tool_call_id patterns
- Usage format conversion (prompt_tokens → input_tokens) for CCR compatibility
- Enhanced logging and debugging capabilities

This unified transformer handles ALL GPT-5 API compatibility requirements.
semikolon added a commit to semikolon/llms that referenced this pull request Aug 23, 2025
…l documentation

✅ MERGED ALL 6 PRs SUCCESSFULLY:
- PR musistudio#28: GPT-5 Core API Compatibility (normalization + tool conversion)
- PR musistudio#29: 2025 Documentation & API Guide (enhanced parameter handling)
- PR musistudio#30: Development Workflow Scripts (automated build processes)

🔧 COMPLETE OPENAI TRANSFORMER:
- Parameter transformations (max_tokens → max_completion_tokens)
- Reasoning parameter handling + verbosity validation
- CRITICAL: normalizeImageContent() + normalizeToolMessages()
- Usage format conversion (OpenAI → Claude Code format)
- Complete tool format conversion with JSON schema cleaning
- Enhanced logging and debugging capabilities

📚 COMPLETE DOCUMENTATION:
- Dev workflow automation scripts
- Comprehensive GPT-5 API compatibility guide
- Local development best practices with yalc

This branch now contains ALL functionality from all 6 PRs!
semikolon added a commit to semikolon/llms that referenced this pull request Aug 23, 2025
- Remove early return statement at line 124 that made lines 125-203 unreachable
- Restores functionality for reasoning parameter conversion, tool format conversion, and verbosity validation
- All PR musistudio#28 and PR musistudio#29 functionality now properly combined in unified branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant