Skip to content

Add configurable base URL for OpenAI-compatible providers#55

Merged
bstanga merged 1 commit intopresubmit:mainfrom
rubenvanerk:openrouter-support
Dec 13, 2025
Merged

Add configurable base URL for OpenAI-compatible providers#55
bstanga merged 1 commit intopresubmit:mainfrom
rubenvanerk:openrouter-support

Conversation

@rubenvanerk
Copy link
Contributor

@rubenvanerk rubenvanerk commented Nov 27, 2025

Summary

Adds support for using OpenRouter and other OpenAI-compatible API providers by allowing users to configure a custom base URL via the LLM_BASE_URL environment variable.

Why: OpenRouter provides rate limiting and cost controls per API key, which is useful for managing expenses across different projects or workflows.

Changes

  • Add LLM_BASE_URL config option (environment variable or GitHub Action input)
  • Pass baseURL to AI SDK provider when configured
  • Skip model whitelist validation when custom base URL is set, enabling use of provider-specific model names (e.g., openai/gpt-4o-mini)
  • Add unit tests for configuration loading
  • Update documentation with usage examples

Implementation Notes

When a custom LLM_BASE_URL is provided, the OpenAI SDK is used regardless of the model name. This works for OpenRouter and other OpenAI-compatible providers, but users should be aware of this assumption.

Note

This implementation bypasses the model whitelist when using a custom base URL. This workaround may become unnecessary after PR #43 is merged, which refactors the model configuration system.

Tested here: rubenvanerk#1

- Add LLM_BASE_URL configuration option (env var or action input)
- Pass baseURL to AI SDK provider when configured
- Skip model whitelist validation when using custom base URL
- Add unit tests for LLM_BASE_URL configuration
- Update documentation with usage examples
@github-actions
Copy link

github-actions bot commented Nov 27, 2025

PR Summary

Added support for configurable base URLs to enable OpenAI-compatible API providers (e.g., OpenRouter, Anyscale, Together AI) via the LLM_BASE_URL environment variable or GitHub Action input. When a custom base URL is provided, the OpenAI SDK is used and model whitelist validation is bypassed to allow provider-specific model names. This feature only applies to the ai-sdk provider and includes comprehensive unit tests and documentation updates.

Changes

File Summary
.env.example Added optional LLM_BASE_URL environment variable example with comment explaining it's for OpenAI-compatible providers when using LLM_PROVIDER=ai-sdk. Includes example URL for OpenRouter.
README.md Added LLM_BASE_URL to required configuration list and created new section explaining how to use OpenRouter and other OpenAI-compatible providers. Includes YAML configuration example and notes that this feature only works with ai-sdk provider. Also added LLM_BASE_URL to local development setup instructions.
dist/cli.js Rebuilt distribution file to include the new LLM_BASE_URL configuration changes.
dist/index.js Rebuilt distribution file to include the new LLM_BASE_URL configuration changes.
src/__tests__/config.test.ts Added three test cases: loading LLM_BASE_URL from environment variable, verifying it's undefined when not set, and loading it from GitHub Action input. Tests cover both configuration sources and default behavior.
src/ai.ts Modified runPrompt function to skip model whitelist validation when config.llmBaseUrl is set and provider is ai-sdk. Creates a fallback modelConfig using createOpenAI to support provider-specific model names when custom base URL is configured.
src/config.ts Added llmBaseUrl property to Config class, loading from LLM_BASE_URL environment variable or llm_base_url action input. Updated mock config to include llmBaseUrl: undefined for test environments.
src/providers/ai-sdk.ts Modified AISDKProvider.infer method to conditionally pass baseURL option to createAiFunc when config.llmBaseUrl is set, enabling custom API endpoints for OpenAI-compatible providers.

autogenerated by presubmit.ai

@rubenvanerk rubenvanerk marked this pull request as ready for review November 27, 2025 09:02
@shawnd
Copy link

shawnd commented Dec 11, 2025

@presubmit

@bstanga
Copy link
Contributor

bstanga commented Dec 13, 2025

Thanks!

@bstanga bstanga merged commit c860450 into presubmit:main Dec 13, 2025
1 check failed
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.

3 participants