#Claude 3.5 message format is not compatible with OpenAI API

20 messages · Page 1 of 1 (latest)

simple laurel
#

I use Spring AI to connect to OpenRouter.

OpenAI or Llama models work fine.

However, when I select the Claude 3.5 model, the following error occurs:

Caused by: com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type org.springframework.ai.openai.api.OpenAiApi$ChatCompletionFinishReason from String "end_turn": not one of the values accepted for Enum class: [stop, function_call, length, content_filter, tool_call, tool_calls]
at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 283, column: 198] (through reference chain: org.springframework.ai.openai.api.OpenAiApi$ChatCompletion["choices"]->java.util.ArrayList[0]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletion$Choice["finish_reason"])

The connection is as a stream and it looks like there is incorrect information coming in as the finish reason.

simple laurel
#

I connected directly to OpenRouter via a python script and sent a streaming request to Sonnet 3.5. And indeed Anthropic or you are returning an incorrect format (finish_reason='end_turn'):

ChatCompletionChunk(id='gen-1729151253-PeKqfipDapE0ksCtCHs6', choices=[Choice(delta=ChoiceDelta(content='', function_call=None, role='assistant', tool_calls=None), finish_reason='end_turn', index=0, logprobs=None)], created=1729151253, model='anthropic/claude-3.5-sonnet:beta', object='chat.completion.chunk', service_tier=None, system_fingerprint=None, usage=None, provider='Anthropic')

green stump
#

Anthropic does not accept requests in which two messages from same role are next to each other. It also does not accept empty text fields in content parts, for example: {type: "text", text: ""}

simple laurel
#

ok, but there is no error in response

#

prompt is correct

#

but instead as OpenAI respond with finish_reason: stop

#

Anthropic respond with finish_reason: end_turn

#

this is from you portal -> Activity -> Generation Details

#

OpenAI response

#

Anthropic response

#

and this is not correct according to OpenAI API specification

#

will you fix it?

#

so that users can connect to the Claude 3.5 model using an OpenAI API-compliant library?

simple laurel
#

will you fix it?

#

because as I understand it, you communicate with Anthropic models via their API and translate the responses to OpenAI API

simple laurel
#

knock, knock