@@ -340,6 +340,7 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
340340 toolCalls := make([]message.ToolCall, 0)
341341 msgToolCalls := make(map[int64]openai.ChatCompletionMessageToolCall)
342342 toolMap := make(map[string]openai.ChatCompletionMessageToolCall)
343+ toolCallIDMap := make(map[string]string)
343344 for openaiStream.Next() {
344345 chunk := openaiStream.Current()
345346 // Kujtim: this is an issue with openrouter qwen, its sending -1 for the tool index
@@ -367,6 +368,15 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
367368 currentContent += choice.Delta.Content
368369 } else if len(choice.Delta.ToolCalls) > 0 {
369370 toolCall := choice.Delta.ToolCalls[0]
371+ if strings.HasPrefix(toolCall.ID, "functions.") {
372+ exID, ok := toolCallIDMap[toolCall.ID]
373+ if !ok {
374+ newID := uuid.NewString()
375+ toolCallIDMap[toolCall.ID] = newID
376+ toolCall.ID = newID
377+ }
378+ toolCall.ID = exID
379+ }
370380 newToolCall := false
371381 if existingToolCall, ok := msgToolCalls[toolCall.Index]; ok { // tool call exists
372382 if toolCall.ID != "" && toolCall.ID != existingToolCall.ID {