fix(oci): uppercase tool type field for OCI V2 API compatibility#758
Merged
daniel-cohere merged 5 commits intocohere-ai:mainfrom Apr 13, 2026
Merged
Conversation
OCI Generative AI expects tool type as "FUNCTION" (uppercase) but the SDK passes through the Cohere format "function" (lowercase), causing a 400 error. Transform tool types to uppercase like we do for message roles and content types.
The missing integration test allowed the tool type casing bug to ship undetected. This test calls OCI with a tool definition and verifies the response contains tool_calls with the correct function name and arguments.
3 tasks
Fix remaining casing issues found during systematic audit: - V1 tools: uppercase type field (same fix as V2) - tool_calls in messages: uppercase type when sending tool results back in multi-turn conversations - Response tool_calls: lowercase type from OCI's "FUNCTION" back to "function" for Cohere SDK compatibility - safety_mode: uppercase defensively (CONTEXTUAL/STRICT/OFF) Integration tests added for each: - test_chat_tool_use_response_type_lowered: verifies tool_call.type is "function" (not "FUNCTION") in responses - test_chat_multi_turn_tool_use_v2: full tool use round-trip (call → result → final response) - test_chat_safety_mode_v2: verifies safety_mode works on OCI
…e response - embedding_types: OCI expects lowercase (float, int8) not uppercase. The .upper() was breaking all embedding_types requests. - Response: OCI returns "embeddingsByType" (not "embeddings") when embeddingTypes is specified. Handle both response keys. - Unit test updated to expect lowercase. - Integration tests added: embedding_types=["float"] and truncate modes.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Reviewed by Cursor Bugbot for commit 1f55765. Configure here.
1f55765 to
8f40152
Compare
Address Cursor Bugbot review: safety_mode is Optional, so the SDK can pass None when the user explicitly sets safety_mode=None. Guard with a None check before calling .upper() on both V1 and V2 paths.
daniel-cohere
approved these changes
Apr 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Fixes #759 —
OciClientV2.chat()withtoolsparameter returns 400 from OCI Generative AI.Root Cause
OCI Generative AI expects the tool
typefield as"FUNCTION"(uppercase), matching its convention for all enum fields (message roles, content types, etc.). The SDK passes through the Cohere format"function"(lowercase), causing:Fix
Transform tool type to uppercase when building the OCI request body, consistent with how we already transform message roles (
"user"→"USER") and content types ("text"→"TEXT").Integration test added
This bug shipped undetected because there was no integration test that called OCI with a
toolsparameter — existing tests only verified request/response transformation with mocked data. Addedtest_chat_tool_use_v2which calls OCI on-demand with a tool definition and asserts:finish_reasonis"TOOL_CALL"tool_callslist is non-emptyget_weather)"Toronto")46/46 non-streaming tests pass. Streaming tests are deselected as the streaming termination fix is in a separate PR (#757).
Test plan
test_chat_tool_use_v2integration test passes against OCI us-chicago-1finish_reason=TOOL_CALLwith correcttool_callstool_planfield populated correctly@daniel-cohere Tool use was broken on OCI because the type field needs to be uppercased like all other OCI enum values. Added the missing integration test so this can't regress.
Note
Medium Risk
Changes request/response transformations for OCI
chatandembed(enum casing and embeddings field selection), which can affect API compatibility and output shape for existing integrations.Overview
Fixes OCI on-demand compatibility by normalizing enum casing in request/response transforms:
toolsandmessage.tool_callsnow uppercase theirtypewhen sending to OCI, while tool calltypeis lowercased on responses for Cohere compatibility;safety_modeis only sent when non-null and is uppercased.Adjusts embeddings handling to match OCI behavior:
embeddingTypesare now sent as lowercase, and embed responses now preferembeddingsByTypewhen present (falling back toembeddings). Adds integration tests covering V2 tool-use (including multi-turn tool results),safety_modebehavior, and embedding options likeembedding_typesandtruncate.Reviewed by Cursor Bugbot for commit 8b2706f. Bugbot is set up for automated code reviews on this repo. Configure here.