Skip to content

Conversation

@taneron
Copy link

@taneron taneron commented Feb 5, 2026

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 feature
    • openai_compatible_api_key: API key for the provider
    • openai_compatible_base_url: Base URL of the API endpoint
    • openai_compatible_model: Model name to use
    • openai_compatible_max_tokens: Maximum response tokens (default: 4096)
  • New Module (run-openai-compatible.ts): Implements the alternative execution path that:

    • Reads prompts and sends them via OpenAI chat completions API
    • Handles URL normalization for different provider formats
    • Includes retry logic (3 attempts with exponential backoff)
    • Returns results in a format compatible with existing infrastructure
    • Writes execution logs to the same output file as Claude SDK
  • Routing Logic (run-claude.ts): Added provider detection and routing:

    • isOpenAICompatibleMode(): Checks if OpenAI-compatible mode is enabled
    • getOpenAICompatibleConfig(): Builds config from environment variables
    • Routes to appropriate execution path based on provider selection
  • Environment Validation (validate-env.ts): Enhanced to:

    • Enforce mutual exclusivity between all providers (Bedrock, Vertex, Foundry, OpenAI-compatible)
    • Validate required OpenAI-compatible variables when enabled
    • Provide clear error messages for missing configuration
  • Execution Flow (run.ts): Optimized to:

    • Skip Claude Code CLI installation when using OpenAI-compatible providers
    • Skip plugin installation for non-Claude providers
    • Maintain compatibility with existing Claude SDK workflows
  • Comprehensive Tests (run-openai-compatible.test.ts): Added 8 test cases covering:

    • URL building for different base URL formats
    • Request header and body validation
    • Successful API responses
    • Error handling and retries
    • Non-success finish reasons

Implementation Details

  • Provider Mutual Exclusivity: Only one provider can be active at a time, enforced at validation time
  • URL Normalization: Intelligently handles base URLs ending with /v1, /v4, or already containing /chat/completions
  • Retry Strategy: Exponential backoff (2s, 4s) for transient failures
  • System Prompt: Includes context about the GitHub Action environment for better model responses
  • Execution Logging: Compatible format with existing Claude SDK output for downstream processing
  • Security: API keys passed via environment variables, full output hidden by default (enable with show_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

Add support for any OpenAI-compatible API (OpenRouter, z.ai, Together,
Groq, etc.) as an alternative to the Claude Code SDK. This enables the
action to work with any model that exposes an OpenAI-style
/chat/completions endpoint.

New action inputs:
- use_openai_compatible: enable OpenAI-compatible mode
- openai_compatible_api_key: API key (store in GitHub Secrets)
- openai_compatible_base_url: API base URL
- openai_compatible_model: model name (e.g., glm-4.7)
- openai_compatible_max_tokens: max response tokens (default 4096)

Also forward ANTHROPIC_AUTH_TOKEN and ANTHROPIC_MODEL env vars for
the existing OpenRouter-via-Claude-Code approach.

https://claude.ai/code/session_013nXy9KcNS5Ag8uajpLgPLo
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.

2 participants