Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- fix: preserve max_tokens for OpenCode-compatible chat endpoints [@Alex-wangyang](https://github.com/Alex-wangyang)
- feat: support Gemini's server-side `toolCall`/`toolResponse` parts with `thoughtSignature` round-trip fidelity - server-side search rounds now surface as `web_search_call` items carrying their own call ID and queries, unmapped tool types are preserved on the native round-trip instead of being dropped, and each `thoughtSignature` appears exactly once across the reconstructed parts so Gemini accepts the replayed turn
- feat: async 3D generation on Runware via `/videos` plus a raw `/runware_passthrough` route - `taskType` is now read from extra_params so any Runware async task can be driven through `/videos` (the 16:9 1080p width/height defaults now apply only to `videoInference`), `outputs.files[].url` is surfaced as `VideoOutput` URLs with the content type derived from the file extension, and the passthrough route forwards raw task arrays for capabilities with no first-class Bifrost surface such as upscaling and background removal
- feat: surface Runware's provider-reported per-task `cost` across image, video/3D and passthrough so pricing uses the exact figure verbatim instead of a datasheet estimate - this matters for task types like 3D that have no datasheet rate; when no cost is reported the behavior is unchanged
Expand Down
9 changes: 9 additions & 0 deletions core/providers/openai/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ func ToOpenAIChatRequest(ctx *schemas.BifrostContext, bifrostReq *schemas.Bifros
openaiReq.filterOpenAISpecificParameters(caps)
openaiReq.applyMistralCompatibility()
return openaiReq
case schemas.OpencodeGo, schemas.OpencodeZen:
openaiReq.filterOpenAISpecificParameters(caps)
// OpenCode's chat-completions endpoints still use the legacy max_tokens
// field and ignore max_completion_tokens.
if openaiReq.MaxCompletionTokens != nil {
openaiReq.MaxTokens = openaiReq.MaxCompletionTokens
openaiReq.MaxCompletionTokens = nil
}
return openaiReq
case schemas.Vertex:
openaiReq.filterOpenAISpecificParameters(caps)

Expand Down
42 changes: 42 additions & 0 deletions core/providers/openai/chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,48 @@ func TestOpenAIInbound_MaxCompletionTokensTakesPriorityOverMaxTokens(t *testing.
}
}

func TestToOpenAIChatRequest_OpencodeUsesLegacyMaxTokensOnWire(t *testing.T) {
tests := []struct {
name string
provider schemas.ModelProvider
}{
{name: "Go", provider: schemas.OpencodeGo},
{name: "Zen", provider: schemas.OpencodeZen},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
bifrostReq := &schemas.BifrostChatRequest{
Provider: tt.provider,
Model: "glm-5.3",
Input: []schemas.ChatMessage{{
Role: schemas.ChatMessageRoleUser,
Content: &schemas.ChatMessageContent{
ContentStr: schemas.Ptr("hello"),
},
}},
Params: &schemas.ChatParameters{
MaxCompletionTokens: schemas.Ptr(512),
},
}

converted := ToOpenAIChatRequest(schemas.NewBifrostContext(nil, schemas.NoDeadline), bifrostReq)
require.NotNil(t, converted)

wireJSON, err := json.Marshal(converted)
require.NoError(t, err)

var wire map[string]json.RawMessage
require.NoError(t, json.Unmarshal(wireJSON, &wire))
require.Contains(t, wire, "max_tokens")
var maxTokens int
require.NoError(t, json.Unmarshal(wire["max_tokens"], &maxTokens))
require.Equal(t, 512, maxTokens)
require.NotContains(t, wire, "max_completion_tokens")
})
}
}

// When a conversation switches from Gemini to OpenAI, Gemini's thoughtSignature is
// embedded in the tool call_id as "<baseID>_ts_<sig>" and can exceed OpenAI's 64-char
// limit. The chat converter must strip it to the base ID on the wire while leaving the
Expand Down