feat(ai): Add support for Snowflake Cortex and OpenAI gateways - #147
feat(ai): Add support for Snowflake Cortex and OpenAI gateways#147almahirpmf wants to merge 1 commit into
Conversation
Added environment variables to allow routing traffic to custom endpoints like Snowflake Cortex, without altering the default behavior for standard OpenAI users. Changes included: - Support for OPENAI_BASE_URL and OPENAI_EXTRA_HEADERS_JSON to override the default api.openai.com endpoint and pass required custom headers. - Added FINALRUN_OPENAI_SNOWFLAKE_COMPAT=1 flag to intercept the underlying fetch call and map max_tokens to max_completion_tokens (required by Snowflake Cortex). - Added FINALRUN_OPENAI_USE_CHAT=1 flag to force the use of Chat Completions (openai.chat) instead of the default Responses API (openai.responses), avoiding 403 errors on /v1/responses for gateways that only support the chat-compatible endpoint. The default behavior for standard OpenAI usage is kept exactly the same.
|
@almahirpmf why is this change required? can you explain, we already support openai |
|
Hi @droid-ash, thanks for taking a look! You're right that OpenAI itself is already supported — this PR is about OpenAI-compatible gateways, which the current openai provider can't reach. Many setups route LLM traffic through a proxy that exposes an OpenAI-compatible endpoint instead of calling api.openai.com directly — Snowflake Cortex, LiteLLM, corporate gateways, etc. In my case I'm running FinalRun against Snowflake Cortex. Three things block FinalRun against such a gateway today:
All three are env-gated and off by default, so stock OpenAI behavior is byte-for-byte identical. With these flags I've been running a full Android test suite through Cortex successfully. Happy to adjust naming/approach if you'd prefer this shaped differently (e.g., a generic openai-compatible provider instead of env flags). |
Summary
Added environment variables to allow routing traffic to custom endpoints like Snowflake Cortex, without altering the default behavior for standard OpenAI users.
Changes included:
Support for OPENAI_BASE_URL and OPENAI_EXTRA_HEADERS_JSON to override the default api.openai.com endpoint and pass required custom headers.
Added FINALRUN_OPENAI_SNOWFLAKE_COMPAT=1 flag to intercept the underlying fetch call and map max_tokens to max_completion_tokens (required by Snowflake Cortex).
Added FINALRUN_OPENAI_USE_CHAT=1 flag to force the use of Chat Completions (openai.chat) instead of the default Responses API (openai.responses), avoiding 403 errors on /v1/responses for gateways that only support the chat-compatible endpoint.
The default behavior for standard OpenAI usage is kept exactly the same.
Validation
npm run buildnpm testnpm run lintManually verified that finalRun successfully connects to Android using Snowflake Cortex as the API key gateway when using the new environment variables.
Notes
Call out platform-specific behavior, follow-up work, or known limitations.