Add OpenAI-compatible API provider support #905
Draft
+748
−20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for OpenAI-compatible API providers (e.g., OpenRouter, z.ai, Together, Groq) as an alternative to the Claude Code SDK. Users can now route prompts through any API that implements the OpenAI chat completions specification.
Key Changes
New Action Inputs: Added four new workflow inputs to configure OpenAI-compatible providers:
use_openai_compatible: Enable/disable the featureopenai_compatible_api_key: API key for the provideropenai_compatible_base_url: Base URL of the API endpointopenai_compatible_model: Model name to useopenai_compatible_max_tokens: Maximum response tokens (default: 4096)New Module (
run-openai-compatible.ts): Implements the alternative execution path that:Routing Logic (
run-claude.ts): Added provider detection and routing:isOpenAICompatibleMode(): Checks if OpenAI-compatible mode is enabledgetOpenAICompatibleConfig(): Builds config from environment variablesEnvironment Validation (
validate-env.ts): Enhanced to:Execution Flow (
run.ts): Optimized to:Comprehensive Tests (
run-openai-compatible.test.ts): Added 8 test cases covering:Implementation Details
/v1,/v4, or already containing/chat/completionsshow_full_output: true)Testing
All new functionality is covered by unit tests with mocked fetch calls. Existing tests updated to account for the new provider option.
https://claude.ai/code/session_013nXy9KcNS5Ag8uajpLgPLo