Skip to content

fix(snowflake): normalize Cortex Claude request shapes - #39453

Merged
tin-berri merged 7 commits into
litellm_internal_stagingfrom
litellm_snowflake_cortex_claude_fixes
Sep 4, 2026
Merged

tin-berri merged 7 commits into
litellm_internal_stagingfrom
litellm_snowflake_cortex_claude_fixes

Conversation

@tin-berri

@tin-berri tin-berri commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Cortex Claude requests lose cache blocks and image structure
  • Streamed tool-call chunks repeat their tool identity
  • Adaptive thinking reaches Cortex models that reject it
  • Cortex prompt-cache usage and thinking blocks never reach the caller

How it solves it:

  • Preserves Anthropic system blocks and normalizes cache controls
  • Converts bridged image and tool-result content back to native blocks
  • Gates adaptive thinking through the provider capability catalog
  • Emits tool identity once per streamed tool call
  • Parses Cortex responses and SSE with Anthropic's own parser

User Flow

Before: a developer sends a Claude-compatible request through the gateway to Snowflake Cortex, but some valid Anthropic inputs arrive in a shape Cortex cannot use

  1. They send POST https://litellm-domain/v1/messages with system caching, an image, or an image tool result
  2. Cortex receives flattened cache data or OpenAI-style image data and either misses caching or rejects the request
  3. When the model streams a tool call, later SSE chunks repeat the tool name and ID
  4. The response usage has only input_tokens and output_tokens, and any thinking block Cortex produced is gone

After: the same request keeps the Anthropic structure Cortex expects

  1. They send the same POST https://litellm-domain/v1/messages request
  2. Cortex receives cache breakpoints with its fixed TTL, and image data as native source blocks
  3. Streamed tool-call identity appears on the start chunk and argument chunks append cleanly
  4. The response usage carries cache_creation_input_tokens / cache_read_input_tokens, and thinking blocks come back with their signature

Relevant issues

Ports and corrects the functional changes from a customer's fork of LiteLLM

Linear ticket

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes local required lint and type gates
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review

Screenshots / Proof of Fix

Live run against a paid Snowflake account (Cortex REST API, real Claude calls) through a local proxy on localhost:4000. Requests hitting Cortex were checked against the outgoing wire body in the --detailed_debug proxy log

Setup

model_list:
  - model_name: snowflake-sonnet-4-6
    litellm_params:
      model: snowflake/claude-sonnet-4-6
      api_key: os.environ/SNOWFLAKE_API_KEY      # pat/<programmatic access token>
      api_base: os.environ/SNOWFLAKE_API_BASE    # https://<org>-<account>.snowflakecomputing.com/api/v2
  - model_name: snowflake-sonnet-4-5
    litellm_params:
      model: snowflake/claude-sonnet-4-5
      api_key: os.environ/SNOWFLAKE_API_KEY
      api_base: os.environ/SNOWFLAKE_API_BASE
P=http://localhost:4000
A=(-H "Authorization: Bearer sk-1234" -H "content-type: application/json")
IMG=$(base64 -w0 red_64x64.png)   # a solid red 64x64 PNG
LONG=$(python3 -c "print('The secret code word is PINEAPPLE. ' * 120)")

After (0f01333)

System cache_control with unsupported ttl, /v1/messages

  1. Command (run twice)

    curl -s $P/v1/messages "${A[@]}" -d "{\"model\":\"snowflake-sonnet-4-6\",\"max_tokens\":30,\"system\":[{\"type\":\"text\",\"text\":\"$LONG\",\"cache_control\":{\"type\":\"ephemeral\",\"ttl\":\"1h\"}}],\"messages\":[{\"role\":\"user\",\"content\":\"What is the secret code word? Reply with one word.\"}]}" | jq -c '{text: .content[0].text, stop_reason, usage}'
  2. Output, first call

    {"text":"PINEAPPLE","stop_reason":"end_turn","usage":{"input_tokens":18,"output_tokens":8,"cache_creation_input_tokens":1323}}
  3. Output, second call

    {"text":"PINEAPPLE","stop_reason":"end_turn","usage":{"input_tokens":18,"output_tokens":8,"cache_read_input_tokens":1323}}
  4. Wire body to /cortex/v1/messages (proxy log): system is a list of text blocks with cache_control: {'type': 'ephemeral'}, ttl stripped

Cache usage on /chat/completions

  1. Command

    curl -s $P/chat/completions "${A[@]}" -d '{"model":"snowflake-sonnet-4-6","max_tokens":30,"messages":[{"role":"user","content":"Say hi in three words"}]}' | jq -c '.usage'
  2. Output

    {"completion_tokens":12,"prompt_tokens":12,"total_tokens":24,"completion_tokens_details":{"reasoning_tokens":0,"text_tokens":12},"prompt_tokens_details":{"cached_tokens":0,"text_tokens":12,"cache_write_tokens":0,"cache_creation_tokens":0,"cache_creation_token_details":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0}},"cache_creation_input_tokens":0,"cache_read_input_tokens":0}

Base64 image, /chat/completions image_url

  1. Command

    curl -s $P/chat/completions "${A[@]}" -d "{\"model\":\"snowflake-sonnet-4-6\",\"max_tokens\":30,\"messages\":[{\"role\":\"user\",\"content\":[{\"type\":\"text\",\"text\":\"What color is this square? One word.\"},{\"type\":\"image_url\",\"image_url\":{\"url\":\"data:image/png;base64,$IMG\"}}]}]}" | jq -c '{content: .choices[0].message.content}'
  2. Output

    {"content":"**Red**"}
  3. Wire body: {'type': 'image', 'source': {'type': 'base64', 'media_type': 'image/png', ...}}

Base64 image, /v1/messages native block

  1. Command

    curl -s $P/v1/messages "${A[@]}" -d "{\"model\":\"snowflake-sonnet-4-6\",\"max_tokens\":30,\"messages\":[{\"role\":\"user\",\"content\":[{\"type\":\"text\",\"text\":\"What color is this square? One word.\"},{\"type\":\"image\",\"source\":{\"type\":\"base64\",\"media_type\":\"image/png\",\"data\":\"$IMG\"}}]}]}" | jq -c '{text: .content[0].text, usage}'
  2. Output

    {"text":"**Red**","usage":{"input_tokens":28,"output_tokens":6}}

Remote URL image, /chat/completions (captured at 4eb7ba3, request path unchanged since)

  1. Command

    curl -s $P/chat/completions "${A[@]}" -d '{"model":"snowflake-sonnet-4-6","max_tokens":40,"messages":[{"role":"user","content":[{"type":"text","text":"Describe this image in five words."},{"type":"image_url","image_url":{"url":"https://httpbin.org/image/png"}}]}]}' | jq -c '{content: .choices[0].message.content}'
  2. Output

    {"content":"Here are five words describing the image:\n\n**Cute, pink, cartoon pig face**"}
  3. Wire body: the URL was fetched and sent as a base64 image block

Image tool_result with cache_control and $schema in the tool, /v1/messages (captured at 4eb7ba3)

  1. Command

    curl -s $P/v1/messages "${A[@]}" -d "{\"model\":\"snowflake-sonnet-4-6\",\"max_tokens\":40,\"tools\":[{\"name\":\"take_screenshot\",\"description\":\"Take a screenshot\",\"input_schema\":{\"\$schema\":\"http://json-schema.org/draft-07/schema#\",\"type\":\"object\",\"properties\":{}}}],\"messages\":[{\"role\":\"user\",\"content\":\"Take a screenshot and tell me the dominant color in one word.\"},{\"role\":\"assistant\",\"content\":[{\"type\":\"tool_use\",\"id\":\"toolu_01\",\"name\":\"take_screenshot\",\"input\":{}}]},{\"role\":\"user\",\"content\":[{\"type\":\"tool_result\",\"tool_use_id\":\"toolu_01\",\"content\":[{\"type\":\"image\",\"source\":{\"type\":\"base64\",\"media_type\":\"image/png\",\"data\":\"$IMG\"}}],\"cache_control\":{\"type\":\"ephemeral\"}}]}]}" | jq -c '{text: .content[0].text, stop_reason, usage}'
  2. Output

    {"text":"**Red.**","stop_reason":"end_turn","usage":{"input_tokens":626,"output_tokens":6}}
  3. Wire body: input_schema has no $schema key, tool_result.content is a native image block

Streamed tool call, /v1/messages (captured at 4eb7ba3)

  1. Command

    curl -s -N $P/v1/messages "${A[@]}" -d '{"model":"snowflake-sonnet-4-6","max_tokens":200,"stream":true,"tools":[{"name":"get_weather","description":"Get weather","input_schema":{"type":"object","properties":{"city":{"type":"string"},"unit":{"type":"string"}},"required":["city","unit"]}}],"tool_choice":{"type":"tool","name":"get_weather"},"messages":[{"role":"user","content":"Weather in Paris in celsius?"}]}' | grep '^data:' | grep -E 'content_block_start|content_block_delta|message_delta' | cut -c7- | jq -c '.'
  2. Output (id and name only on content_block_start)

    {"type":"content_block_start","index":0,"content_block":{"type":"tool_use","id":"toolu_bdrk_01Ecbti1FXaXwm6VFDYeRgcS","name":"get_weather","input":{}}}
    {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":"{\"city\": \"Pa"}}
    {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":"ris\""}}
    {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":", \""}}
    {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":"unit\""}}
    {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":": \"c"}}
    {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":"elsius\"}"}}
    {"type":"message_delta","delta":{"stop_reason":"tool_use"},"usage":{"input_tokens":670,"output_tokens":50}}

Streamed tool call, /chat/completions (captured at 4eb7ba3)

  1. Command

    curl -s -N $P/chat/completions "${A[@]}" -d '{"model":"snowflake-sonnet-4-6","max_tokens":200,"stream":true,"tools":[{"type":"function","function":{"name":"get_weather","parameters":{"$schema":"http://json-schema.org/draft-07/schema#","type":"object","properties":{"city":{"type":"string"},"unit":{"type":"string"}},"required":["city","unit"]}}}],"tool_choice":"required","messages":[{"role":"user","content":"Weather in Paris in celsius?"}]}' | grep '^data:' | grep -v '\[DONE\]' | cut -c7- | jq -c 'select(.choices[0].delta.tool_calls != null) | .choices[0].delta.tool_calls[0]'
  2. Output

    {"id":"toolu_bdrk_012RHaaqLtGfMxKyBzUVVp7Z","function":{"arguments":"","name":"get_weather"},"type":"function","index":0}
    {"function":{"arguments":""},"type":"function","index":0}
    {"function":{"arguments":"{\"city\": \"P"},"type":"function","index":0}
    {"function":{"arguments":"aris\""},"type":"function","index":0}
    {"function":{"arguments":", \"uni"},"type":"function","index":0}
    {"function":{"arguments":"t\""},"type":"function","index":0}
    {"function":{"arguments":": \"ce"},"type":"function","index":0}
    {"function":{"arguments":"lsius\"}"},"type":"function","index":0}

Thinking on claude-sonnet-4-6, /v1/messages (captured at 4eb7ba3)

  1. Command

    curl -s $P/v1/messages "${A[@]}" -d '{"model":"snowflake-sonnet-4-6","max_tokens":2000,"thinking":{"type":"enabled","budget_tokens":1024},"messages":[{"role":"user","content":"What is 17*23? Answer with the number only."}]}' | jq -c '{text: [.content[] | select(.type=="text") | .text], usage}'
  2. Output

    {"text":["391"],"usage":{"input_tokens":49,"output_tokens":13}}
  3. Raw Cortex response in the proxy log: content=[{"type":"thinking","thinking":"391","signature":"Eto..."},{"type":"text","text":"391"}]

Type

Bug Fix

Caveats (if any)

Low

  • The shared Anthropic-transform refactor is tracked separately in LIT-6778
  • Extended thinking is allowed on every Cortex Claude model, only type: adaptive is 4.6-gated

Link to Devin session: https://app.devin.ai/sessions/49ef770df35a4bbf990a167166f399cf
Open in Devin Desktop: https://app.devin.ai/desktop/session/49ef770df35a4bbf990a167166f399cf?variant=devin


Note

Medium Risk
Touches message transformation, tool/streaming behavior, and usage accounting on a provider path; regressions could break Claude-on-Cortex or billing visibility, but changes reuse well-tested Anthropic shared code and are heavily covered by new tests.

Overview
Aligns Snowflake Cortex Claude (/cortex/v1/messages) with the rest of LiteLLM’s Anthropic dialects so bridged OpenAI/Anthropic clients send wire shapes Cortex accepts and get full responses back.

Outgoing requests now emit Anthropic-style system as text blocks (with cache_control normalized and unsupported ttl stripped), convert image_url and multipart tool results to native image/document blocks (base64 inlining), preserve signed thinking blocks on follow-up turns, strip top-level $schema from tool schemas, and honor an explicit system optional param when provided.

Responses and streaming delegate to shared AnthropicConfig / AnthropicStreamParser instead of bespoke parsers, so thinking / reasoning, prompt-cache usage in prompt_tokens_details, and streamed tool-call chunks (id/name only on content_block_start) match other Anthropic providers. thinking is advertised in supported params for all Cortex Claude models.

Reviewed by Cursor Bugbot for commit 74c7bb5. Bugbot is set up for automated code reviews on this repo. Configure here.

@devin-ai-integration devin-ai-integration Bot added the risk:medium Moderate-risk functional change label Sep 3, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

PR #39453 labeled risk:medium (5 files, +351/-44; isolated Snowflake Cortex translation fix plus model-pricing JSON edits, no sensitive areas). No enterprise label, so Linear routing was skipped.

@codspeed

codspeed Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_snowflake_cortex_claude_fixes (74c7bb5) with litellm_internal_staging (cf3af0f)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR normalizes Snowflake Cortex Claude request, response, and streaming shapes using shared Anthropic conversion logic.

  • Preserves cache controls, images, documents, tool results, and signed thinking blocks.
  • Delegates response and stream parsing to shared Anthropic helpers.
  • Adds focused Snowflake transformation and native-endpoint coverage.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains.

No blocking failure remains.

Important Files Changed

Filename Overview
litellm/llms/snowflake/chat/transformation.py Adds Cortex Claude normalization and shared Anthropic parsing.
tests/test_litellm/llms/snowflake/chat/test_snowflake_chat_transformation.py Adds request, response, cache, media, thinking, and streaming transformation coverage.
tests/test_litellm/llms/snowflake/test_snowflake_native_endpoints.py Extends native Snowflake endpoint coverage for the normalized Claude behavior.

Reviews (4): Last reviewed commit: "fix(snowflake): surface Cortex prompt-ca..." | Re-trigger Greptile

def _extract_system_and_messages(self, messages: list[AllMessageValues]) -> tuple[str | None, list[dict]]:
def _extract_system_and_messages( # mutable-ok: JSON wire messages
self, messages: list[AllMessageValues]
) -> tuple[list[dict] | None, list[dict]]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Inconsistent Python type discipline

The new normalization code uses coarse list[dict] types, mutates optional_params without the required suppression, and adds lines beyond 120 characters, weakening type checking and maintainability across this adapter

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed on 4eb7ba3. The new path now delegates to the shared Anthropic converters, removing the coarse hand-rolled conversion; lint and type-budget gates pass.

@codecov

codecov Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.94595% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/llms/snowflake/chat/transformation.py 95.94% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai Please re-review the latest commit and provide a confidence score.

@tin-berri
tin-berri force-pushed the litellm_snowflake_cortex_claude_fixes branch 2 times, most recently from 9085678 to 49ea24c Compare September 3, 2026 01:37
tin-berri and others added 3 commits September 2, 2026 19:22
Co-authored-by: Kamron Javaherpour <kamron@kargo.com>

Co-authored-by: Oleksandr Kononov <oleks.konov@kargo.com>
@tin-berri
tin-berri force-pushed the litellm_snowflake_cortex_claude_fixes branch from 49ea24c to b536eeb Compare September 3, 2026 02:23
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with score and why

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Confidence score: 5/5.

The latest revision correctly addresses the requested Cortex Claude translation issues: structured system blocks and cache controls are preserved and normalized, bridged images/tool results are converted back to Anthropic-native blocks, thinking support is gated by the model capability catalog, and streamed tool identity is emitted only on content_block_start. The added tests cover each behavior, including direct system passthrough, multipart tool results, schema cleanup, and streaming deltas. The prior style/type concerns were also addressed, and the reported patch coverage is 98% with no blocking correctness issue identified.

if not isinstance(image_url_value, str) or not image_url_value:
return dict(block) # mutable-ok: JSON wire block

image: Final = convert_to_anthropic_image_obj(openai_image_url=image_url_value, format=image_format)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low: Unbounded image downloads block request workers

An authenticated user can submit many image_url blocks pointing to slow public servers, and each URL is downloaded synchronously here before the asynchronous provider call. Although each image is size-limited, there is no limit on the number or cumulative size of downloads, so one request can tie up a worker and consume substantial outbound bandwidth; enforce per-request image/count and cumulative-byte limits and use asynchronous fetching with a dedicated short timeout, or require data URIs for this provider.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed holistically at the seam: this path now delegates to the shared Anthropic converters instead of calling the low-level base64 helper, so it inherits any download budget added there. Cortex documents base64 sources only, so remote URLs must still be inlined exactly as Bedrock invoke and Vertex inline them. Capping per-request image count and cumulative bytes belongs in that shared helper, not one provider; filing it separately.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detail. I can't automatically confirm this is safe to dismiss, so I'm leaving the thread open for a maintainer to make the call.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up: the concern is valid for the shared remote-image fetch primitive. This PR now uses that shared primitive; a cross-provider budget and timeout change needs separate scope, so the maintainer decision remains open.

@veria-ai

veria-ai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

PR overview

This PR normalizes Claude request payload shapes for Snowflake Cortex chat, including transforming image URL content into provider-compatible input.

One security concern remains in image handling: an authenticated user can submit many slow image URLs, tying up synchronous request workers and consuming outbound bandwidth. No security issues have yet been addressed, and per-request download limits or safer fetching controls are still needed.

Open issues (1)

Fixed/addressed: 0 · PR risk: 5/10

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai Please re-review the latest commit and provide a confidence score.

@tin-berri

Copy link
Copy Markdown
Contributor Author

@veria-ai Please re-review the latest commit.

@tin-berri

Copy link
Copy Markdown
Contributor Author

@cursor Bugbot Please re-review the latest commit.

@cursor

cursor Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

You need to increase your spend limit or enable usage-based billing to run background agents. Go to Cursor

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 4eb7ba3. Configure here.

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snowflake documents extended thinking (budget_tokens) for the Messages API; only adaptive thinking is 4.6-gated. Two thinking findings below block merge.

"tool_choice",
]
if _is_claude_model(model):
if _is_claude_model(model) and AnthropicModelInfo._is_adaptive_thinking_model(model, "snowflake"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snowflake's Messages API docs list extended thinking (budget_tokens) alongside adaptive; only adaptive is 4.6-gated. This silently drops thinking for sonnet-4-5, 4-sonnet, haiku-4-5.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, fixed on 0f01333. The 4.6 gate is gone; thinking is advertised for every Claude model again, since only adaptive thinking is 4.6-gated. Test asserts sonnet-4-5, 4-opus and 3-7-sonnet all keep it.

Comment thread model_prices_and_context_window.json Outdated
"supports_response_schema": true,
"prompt_cache_min_tokens": 1024
"prompt_cache_min_tokens": 1024,
"supports_reasoning": false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every other provider keeps claude-sonnet-4-5 reasoning-capable, and Snowflake's own reasoning example uses this model. These flips make supports_reasoning wrong for five entries.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, reverted on 0f01333. Both model-price maps are now byte-identical to staging, so the five supports_reasoning flips are gone entirely and the capability question stays out of this PR.

@mateo-berri mateo-berri left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is any live QA against live Cortex.

Parse Cortex's Anthropic-dialect responses and SSE with Anthropic's own parser so cache_creation/cache_read counts, thinking blocks and signatures reach the caller. Restore thinking for every Claude model: Cortex documents extended thinking broadly and only adaptive thinking is 4.6-gated.
@tin-berri

Copy link
Copy Markdown
Contributor Author

Latest commit 0f01333 fixes the two E2E response-side gaps and both blocking review findings.

  • Prompt-cache usage now surfaces: Cortex cache_creation/cache_read counts flow into prompt_tokens_details, so caching is visible and billed correctly.
  • Thinking blocks and signatures are preserved on both streaming and non-streaming, and signed blocks are echoed back first on the next assistant turn.
  • Thinking is advertised for every Claude model again; only adaptive thinking is 4.6-gated.
  • Both model-price maps are reverted to staging.

Cortex responses and SSE are now parsed by Anthropic own parser rather than a hand-rolled one, which is what closes these as a class.

Open item: I could not reproduce the extra empty tool-arguments chunk. Same synthetic stream is clean before and after the change, so I would need the raw SSE from that run to chase it.

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai Please re-review the latest commit and provide a confidence score.

@tin-berri

Copy link
Copy Markdown
Contributor Author

@cursor Bugbot Please re-review the latest commit.

@cursor

cursor Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

You need to increase your spend limit or enable usage-based billing to run background agents. Go to Cursor

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Live QA against Snowflake Cortex

Live run against a paid Snowflake account (Cortex REST API, real Claude calls) through a local proxy on localhost:4000. Requests hitting Cortex were checked against the outgoing wire body in the --detailed_debug proxy log

Setup

model_list:
  - model_name: snowflake-sonnet-4-6
    litellm_params:
      model: snowflake/claude-sonnet-4-6
      api_key: os.environ/SNOWFLAKE_API_KEY      # pat/<programmatic access token>
      api_base: os.environ/SNOWFLAKE_API_BASE    # https://<org>-<account>.snowflakecomputing.com/api/v2
  - model_name: snowflake-sonnet-4-5
    litellm_params:
      model: snowflake/claude-sonnet-4-5
      api_key: os.environ/SNOWFLAKE_API_KEY
      api_base: os.environ/SNOWFLAKE_API_BASE
P=http://localhost:4000
A=(-H "Authorization: Bearer sk-1234" -H "content-type: application/json")
IMG=$(base64 -w0 red_64x64.png)   # a solid red 64x64 PNG
LONG=$(python3 -c "print('The secret code word is PINEAPPLE. ' * 120)")

After (0f01333)

System cache_control with unsupported ttl, /v1/messages

  1. Command (run twice)

    curl -s $P/v1/messages "${A[@]}" -d "{\"model\":\"snowflake-sonnet-4-6\",\"max_tokens\":30,\"system\":[{\"type\":\"text\",\"text\":\"$LONG\",\"cache_control\":{\"type\":\"ephemeral\",\"ttl\":\"1h\"}}],\"messages\":[{\"role\":\"user\",\"content\":\"What is the secret code word? Reply with one word.\"}]}" | jq -c '{text: .content[0].text, stop_reason, usage}'
  2. Output, first call

    {"text":"PINEAPPLE","stop_reason":"end_turn","usage":{"input_tokens":18,"output_tokens":8,"cache_creation_input_tokens":1323}}
  3. Output, second call

    {"text":"PINEAPPLE","stop_reason":"end_turn","usage":{"input_tokens":18,"output_tokens":8,"cache_read_input_tokens":1323}}
  4. Wire body to /cortex/v1/messages (proxy log): system is a list of text blocks with cache_control: {'type': 'ephemeral'}, ttl stripped

Cache usage on /chat/completions

  1. Command

    curl -s $P/chat/completions "${A[@]}" -d '{"model":"snowflake-sonnet-4-6","max_tokens":30,"messages":[{"role":"user","content":"Say hi in three words"}]}' | jq -c '.usage'
  2. Output

    {"completion_tokens":12,"prompt_tokens":12,"total_tokens":24,"completion_tokens_details":{"reasoning_tokens":0,"text_tokens":12},"prompt_tokens_details":{"cached_tokens":0,"text_tokens":12,"cache_write_tokens":0,"cache_creation_tokens":0,"cache_creation_token_details":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0}},"cache_creation_input_tokens":0,"cache_read_input_tokens":0}

Base64 image, /chat/completions image_url

  1. Command

    curl -s $P/chat/completions "${A[@]}" -d "{\"model\":\"snowflake-sonnet-4-6\",\"max_tokens\":30,\"messages\":[{\"role\":\"user\",\"content\":[{\"type\":\"text\",\"text\":\"What color is this square? One word.\"},{\"type\":\"image_url\",\"image_url\":{\"url\":\"data:image/png;base64,$IMG\"}}]}]}" | jq -c '{content: .choices[0].message.content}'
  2. Output

    {"content":"**Red**"}
  3. Wire body: {'type': 'image', 'source': {'type': 'base64', 'media_type': 'image/png', ...}}

Base64 image, /v1/messages native block

  1. Command

    curl -s $P/v1/messages "${A[@]}" -d "{\"model\":\"snowflake-sonnet-4-6\",\"max_tokens\":30,\"messages\":[{\"role\":\"user\",\"content\":[{\"type\":\"text\",\"text\":\"What color is this square? One word.\"},{\"type\":\"image\",\"source\":{\"type\":\"base64\",\"media_type\":\"image/png\",\"data\":\"$IMG\"}}]}]}" | jq -c '{text: .content[0].text, usage}'
  2. Output

    {"text":"**Red**","usage":{"input_tokens":28,"output_tokens":6}}

Remote URL image, /chat/completions (captured at 4eb7ba3, request path unchanged since)

  1. Command

    curl -s $P/chat/completions "${A[@]}" -d '{"model":"snowflake-sonnet-4-6","max_tokens":40,"messages":[{"role":"user","content":[{"type":"text","text":"Describe this image in five words."},{"type":"image_url","image_url":{"url":"https://httpbin.org/image/png"}}]}]}' | jq -c '{content: .choices[0].message.content}'
  2. Output

    {"content":"Here are five words describing the image:\n\n**Cute, pink, cartoon pig face**"}
  3. Wire body: the URL was fetched and sent as a base64 image block

Image tool_result with cache_control and $schema in the tool, /v1/messages (captured at 4eb7ba3)

  1. Command

    curl -s $P/v1/messages "${A[@]}" -d "{\"model\":\"snowflake-sonnet-4-6\",\"max_tokens\":40,\"tools\":[{\"name\":\"take_screenshot\",\"description\":\"Take a screenshot\",\"input_schema\":{\"\$schema\":\"http://json-schema.org/draft-07/schema#\",\"type\":\"object\",\"properties\":{}}}],\"messages\":[{\"role\":\"user\",\"content\":\"Take a screenshot and tell me the dominant color in one word.\"},{\"role\":\"assistant\",\"content\":[{\"type\":\"tool_use\",\"id\":\"toolu_01\",\"name\":\"take_screenshot\",\"input\":{}}]},{\"role\":\"user\",\"content\":[{\"type\":\"tool_result\",\"tool_use_id\":\"toolu_01\",\"content\":[{\"type\":\"image\",\"source\":{\"type\":\"base64\",\"media_type\":\"image/png\",\"data\":\"$IMG\"}}],\"cache_control\":{\"type\":\"ephemeral\"}}]}]}" | jq -c '{text: .content[0].text, stop_reason, usage}'
  2. Output

    {"text":"**Red.**","stop_reason":"end_turn","usage":{"input_tokens":626,"output_tokens":6}}
  3. Wire body: input_schema has no $schema key, tool_result.content is a native image block

Streamed tool call, /v1/messages (captured at 4eb7ba3)

  1. Command

    curl -s -N $P/v1/messages "${A[@]}" -d '{"model":"snowflake-sonnet-4-6","max_tokens":200,"stream":true,"tools":[{"name":"get_weather","description":"Get weather","input_schema":{"type":"object","properties":{"city":{"type":"string"},"unit":{"type":"string"}},"required":["city","unit"]}}],"tool_choice":{"type":"tool","name":"get_weather"},"messages":[{"role":"user","content":"Weather in Paris in celsius?"}]}' | grep '^data:' | grep -E 'content_block_start|content_block_delta|message_delta' | cut -c7- | jq -c '.'
  2. Output (id and name only on content_block_start)

    {"type":"content_block_start","index":0,"content_block":{"type":"tool_use","id":"toolu_bdrk_01Ecbti1FXaXwm6VFDYeRgcS","name":"get_weather","input":{}}}
    {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":"{\"city\": \"Pa"}}
    {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":"ris\""}}
    {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":", \""}}
    {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":"unit\""}}
    {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":": \"c"}}
    {"type":"content_block_delta","index":0,"delta":{"type":"input_json_delta","partial_json":"elsius\"}"}}
    {"type":"message_delta","delta":{"stop_reason":"tool_use"},"usage":{"input_tokens":670,"output_tokens":50}}

Streamed tool call, /chat/completions (captured at 4eb7ba3)

  1. Command

    curl -s -N $P/chat/completions "${A[@]}" -d '{"model":"snowflake-sonnet-4-6","max_tokens":200,"stream":true,"tools":[{"type":"function","function":{"name":"get_weather","parameters":{"$schema":"http://json-schema.org/draft-07/schema#","type":"object","properties":{"city":{"type":"string"},"unit":{"type":"string"}},"required":["city","unit"]}}}],"tool_choice":"required","messages":[{"role":"user","content":"Weather in Paris in celsius?"}]}' | grep '^data:' | grep -v '\[DONE\]' | cut -c7- | jq -c 'select(.choices[0].delta.tool_calls != null) | .choices[0].delta.tool_calls[0]'
  2. Output

    {"id":"toolu_bdrk_012RHaaqLtGfMxKyBzUVVp7Z","function":{"arguments":"","name":"get_weather"},"type":"function","index":0}
    {"function":{"arguments":""},"type":"function","index":0}
    {"function":{"arguments":"{\"city\": \"P"},"type":"function","index":0}
    {"function":{"arguments":"aris\""},"type":"function","index":0}
    {"function":{"arguments":", \"uni"},"type":"function","index":0}
    {"function":{"arguments":"t\""},"type":"function","index":0}
    {"function":{"arguments":": \"ce"},"type":"function","index":0}
    {"function":{"arguments":"lsius\"}"},"type":"function","index":0}

Thinking on claude-sonnet-4-6, /v1/messages (captured at 4eb7ba3)

  1. Command

    curl -s $P/v1/messages "${A[@]}" -d '{"model":"snowflake-sonnet-4-6","max_tokens":2000,"thinking":{"type":"enabled","budget_tokens":1024},"messages":[{"role":"user","content":"What is 17*23? Answer with the number only."}]}' | jq -c '{text: [.content[] | select(.type=="text") | .text], usage}'
  2. Output

    {"text":["391"],"usage":{"input_tokens":49,"output_tokens":13}}
  3. Raw Cortex response in the proxy log: content=[{"type":"thinking","thinking":"391","signature":"Eto..."},{"type":"text","text":"391"}]

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

The reference converter extends signed thinking blocks on each assistant turn, not just tool-call turns, so a replayed thinking-plus-text response keeps its signed block. Content-less thinking turns send no empty text block.
@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with score pls and why

@greptile-apps

greptile-apps Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Confidence score: 4/5.

The changes directly address the reported Cortex issues: Anthropic-shaped system/cache blocks are preserved and normalized, images and tool results are converted to native blocks, adaptive thinking is capability-gated, signed thinking blocks round-trip, and the shared Anthropic response/SSE parsers now preserve cache usage, reasoning, and one-time streamed tool identity. The added tests cover these request, response, and streaming cases, and the live Cortex checks provide additional evidence.

I’m not giving 5/5 because this changes the wire format and parsing path for all Snowflake Claude traffic, while most automated coverage is unit-level rather than full end-to-end coverage across less common content combinations, multiple tool calls, and all streaming event sequences.

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with score & why

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Confidence score: 4/5

The fix is well-scoped and addresses the reported behaviors end to end: Anthropic system/cache blocks are preserved, images and tool results are normalized, adaptive thinking is capability-gated, streamed tool identity is emitted only once, and Cortex responses/SSE are parsed through the Anthropic implementations. The targeted tests plus live Snowflake validation provide strong evidence for caching, vision, tool calls, thinking, and usage fields.

I’m reserving 5/5 because this touches shared conversion, streaming, and billing-related parsing paths, so the remaining risk is regression in less common multi-turn/mixed-content cases or provider-wide behavior not covered by the shown evidence.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 74c7bb5. Configure here.

@tin-berri
tin-berri enabled auto-merge (squash) September 4, 2026 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:medium Moderate-risk functional change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants