Skip to content

Conversation

@blackjr21
Copy link

Summary

xAI deprecated the /v1/chat/completions endpoint which now returns 410 "Live search is deprecated". This PR migrates grok-cli to use the /v1/responses endpoint.

Changes

src/grok/client.ts

  1. chat() method - Now uses /v1/responses with native fetch instead of OpenAI SDK's chat.completions.create()

  2. Tool format conversion - Flattened from nested structure:

    // Before (OpenAI format)
    { type: "function", function: { name, description, parameters } }
    
    // After (xAI Responses API format)  
    { type: "function", name, description, parameters }
  3. Response parsing - Added convertResponseToGrokResponse() to extract text from xAI's response format:

    output[].content[].text  // where type === "output_text"
  4. Streaming - Rewrote chatStream() to parse SSE format from Responses API:

    event: response.output_text.delta
    data: {"delta": "Hello"}
    

    Handles event types:

    • response.output_text.delta - Main content streaming
    • response.content_part.delta - Alternative content format
    • response.output_item.added/done - Tool calls
    • response.completed/done - Response finished

Testing

Tested and working:

  • ✅ Basic chat (headless mode: grok -p "hello")
  • ✅ Interactive mode (grok)
  • ✅ Tool calling (view_file, bash, create_file, str_replace_editor)
  • ✅ Streaming responses

Related Issues

Fixes #134

Notes

xAI deprecated the /v1/chat/completions endpoint (returns 410 "Live search
is deprecated"). This PR migrates to the /v1/responses endpoint.

Changes:
- chat() now uses /v1/responses with fetch instead of OpenAI SDK
- chatStream() parses SSE events (event: + data: format) from Responses API
- Tool format flattened: {type, name, description, parameters} instead of
  nested {type, function: {name, description, parameters}}
- Response parsing extracts text from output[].content[].text
- Added convertResponseToGrokResponse() for backward compatibility
- Added convertStreamChunk() to handle SSE event types:
  - response.output_text.delta (main content)
  - response.content_part.delta (alternative content)
  - response.output_item.added/done (tool calls)
  - response.completed/done (finish)

Fixes superagent-ai#134

Tested with:
- Basic chat (headless & interactive modes)
- Tool calling (view_file, bash, create_file)
- Streaming responses
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Grok API Deprecated methods

3 participants