Skip to content

Conversation

joolab
Copy link

@joolab joolab commented Jul 4, 2025

What:

  • Bug Fix
  • New Feature

Description:

GrokAI API returns an error as a string, rather than as an object, as the original OpenAI API does. I propose this adjustment to make the library compatible with the GrokAI API.

… returns an error as an object), Grok API returns errors as strings. Added support for this format to ensure compatibility with Grok.
@iBotPeaches iBotPeaches added the Non-OpenAI Model Not an OpenAI Model. label Jul 4, 2025
@iBotPeaches
Copy link
Collaborator

Do you have a sample of the payload structure or doc link? I haven't used Grok at all yet.

@joolab
Copy link
Author

joolab commented Jul 4, 2025

Do you have a sample of the payload structure or doc link? I haven't used Grok at all yet.

They claim that their API is fully compatible with the OpenAI REST API.

https://docs.x.ai/docs/api-reference

@iBotPeaches
Copy link
Collaborator

Do you have a sample response? What you've changed is like the root level parsing of a response into JSON to make that a string which doesn't seem right. I imagine its still JSON, but with a string on error?

The sample will help

@iBotPeaches iBotPeaches changed the title Error handling from GrokAI API fix(Grok): Error handling from GrokAI API Jul 4, 2025
@joolab
Copy link
Author

joolab commented Jul 4, 2025

Do you have a sample response? What you've changed is like the root level parsing of a response into JSON to make that a string which doesn't seem right. I imagine its still JSON, but with a string on error?

The sample will help

GrokAI:
{"code":"400","error":"Bad data: Messages cannot be empty"}

OpenAI:

{
  "error": {
    "message": "Invalid 'messages': empty array. Expected an array with minimum length 1, but got an empty array instead.",
    "type": "invalid_request_error",
    "param": "messages",
    "code": "empty_array"
  }
}

@iBotPeaches
Copy link
Collaborator

Okay thanks. So we can probably look for code and error at root and detect this as an error. With a change like that and a change to our test suite - we could merge this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Non-OpenAI Model Not an OpenAI Model.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants