Note, I was able to solve my issue by using the useChat experimental_prepareRequestBody function. Now instead of adding the data in the handleSubmit function I add it via this function.
experimental_prepareRequestBody({ id, messages, requestBody }) {
const selectedModelValue = toValue(selectedModel);
if (!selectedModelValue) {
throw new Error('No model selected');
}
const modelId = selectedModelValue.providerModelId;
if (!modelId) {
throw new Error('No model ID found');
}
return {
id,
messages,
...requestBody,
modelId,
};
},