Skip to content

feat(core): add Snowflake Cortex provider#29901

Open
kameshsampath wants to merge 6 commits into
anomalyco:devfrom
kameshsampath:feat/provider/snowflake-cortex
Open

feat(core): add Snowflake Cortex provider#29901
kameshsampath wants to merge 6 commits into
anomalyco:devfrom
kameshsampath:feat/provider/snowflake-cortex

Conversation

@kameshsampath
Copy link
Copy Markdown

@kameshsampath kameshsampath commented May 29, 2026

Issue for this PR

Closes #29900

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Snowflake Cortex exposes an OpenAI-compatible endpoint but can't be supported with a models.dev entry alone. Three things require code:

  1. The endpoint URL is per-account (https://${SNOWFLAKE_ACCOUNT}.snowflakecomputing.com/api/v2/cortex/v1) — no static URL to put in models.dev
  2. The API uses max_completion_tokens instead of max_tokens
  3. HTTP 400 "conversation complete" is a normal stop condition, not an error

Changes:

  • provider.ts custom() loader: dynamic baseURL, credential resolution from env/auth store/config, fetch interceptor for the two quirks above
  • packages/core SnowflakeCortexPlugin: same via the V2 aisdk.sdk hook, registered before OpenAICompatiblePlugin
  • providers.ts: dedicated login flow that prompts for both account identifier and PAT, stores both in auth metadata so opencode auth login is self-contained

Companion models.dev PR: anomalyco/models.dev#1902

How did you verify your code works?

Tested end-to-end with bun dev against a real Snowflake account — chat and tool-use requests work with claude-sonnet-4-6. The max_completion_tokens rewrite and conversation-complete handling were confirmed by observing requests and responses.

11 tests in packages/core/test/plugin/provider-snowflake-cortex.test.ts cover the fetch interceptor and plugin hook behaviors.

Screenshots / recordings

No UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels May 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@rekram1-node rekram1-node marked this pull request as ready for review May 29, 2026 15:22
@rekram1-node
Copy link
Copy Markdown
Collaborator

rekram1-node commented May 29, 2026

whoops accidentally moved it out of draft didnt mean to click that my bad

Ill monitor all ur prs so whenever they are ready we can merge them all

@kameshsampath
Copy link
Copy Markdown
Author

thanks @rekram1-node appreciate your quick response, I shared the PR with my peers and waiting for their comments/improvements if any before I can turn it ready. Does that sound OK ? and same with anomalyco/models.dev#1902.

Is there any SLA to move from DRAFT to READY for review?

@rekram1-node rekram1-node marked this pull request as draft May 29, 2026 16:47
@rekram1-node
Copy link
Copy Markdown
Collaborator

You can just @ me when they are ready or move them out of draft, I moved this pr back to draft for u

Snowflake Cortex uses a per-account endpoint URL and has two API quirks
that require explicit handling: it expects max_completion_tokens instead
of max_tokens, and returns 400 "conversation complete" as a normal stop
condition rather than a finish_reason.

Changes:
- custom() loader in provider.ts: resolves baseURL from SNOWFLAKE_ACCOUNT,
  PAT from SNOWFLAKE_CORTEX_PAT or opencode auth store, fetch interceptor
  rewrites max_tokens and handles conversation complete
- SnowflakeCortexPlugin in packages/core: V2 plugin for the aisdk.sdk
  hook with the same fetch interceptor; registered before OpenAICompatiblePlugin
- providers.ts: dedicated login flow that collects and stores both account
  identifier and PAT via opencode auth

Companion models.dev PR: anomalyco/models.dev#1902

.... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code)

Co-Authored-By: Cortex Code <noreply@snowflake.com>
@kameshsampath kameshsampath force-pushed the feat/provider/snowflake-cortex branch from addc405 to 691d703 Compare May 30, 2026 03:36
…to V2 plugin

Cortex returns role:"" in streaming delta chunks for GPT-5 models; the AI
SDK schema validation rejects this because the only valid value is "assistant".
The legacy provider.ts already had the SSE normalizer but used
decoder.decode() without { stream: true }, which corrupts multi-byte chars
at chunk boundaries.

- Fix decoder.decode to use { stream: true } in provider.ts
- Add the same SSE normalizer to cortexFetch in the V2 plugin
- Add test for the role normalization

.... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code)

Co-Authored-By: Cortex Code <noreply@snowflake.com>
@kameshsampath kameshsampath marked this pull request as ready for review May 30, 2026 03:59
@kameshsampath
Copy link
Copy Markdown
Author

kameshsampath commented May 30, 2026

@rekram1-node please review when you can and can you help with related anomalyco/models.dev#1902?

Adds setup guide for Snowflake Cortex to the providers page, covering
the /connect flow, env var alternative, and a sample opencode.json with
model capability flags.

.... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code)

Co-Authored-By: Cortex Code <noreply@snowflake.com>
@rekram1-node
Copy link
Copy Markdown
Collaborator

yep

- Add trial signup link with UTM tracking
- Link to official account identifier and trial account docs
- Clarify that the provider is limited to tool-calling capable models
- Simplify opencode.json example to rely on models.dev catalog
- Remove em dashes and stale model list
@kameshsampath
Copy link
Copy Markdown
Author

added docs and updated the PR @rekram1-node

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.

[FEATURE]: Add Snowflake Cortex provider

2 participants