Skip to content

Conversation

@junghan0611
Copy link

Summary

Add OpenRouter backend support to efrit-chat.el, enabling the chat interface to work with OpenRouter API in addition to the existing Anthropic API.

Changes

  • Add efrit--get-model to select model based on efrit-api-backend
  • Use efrit-common-build-headers for backend-specific HTTP headers
  • Add efrit--build-request-data for Anthropic/OpenRouter format switching
  • Add efrit--parse-openrouter-response for OpenAI-compatible responses
  • Extract tools schema to efrit--tools-schema constant
  • Add efrit--convert-tools-for-openrouter for tool format conversion

Usage

;; Configure for OpenRouter
(setq efrit-api-backend 'openrouter)
(setq efrit-api-auth-source-host "openrouter.ai")
(setq efrit-api-auth-source-user "apikey")
(setq efrit-model-openrouter "anthropic/claude-sonnet-4")

;; Start chat
M-x efrit-chat

Compatibility

  • Maintains full backward compatibility with Anthropic backend
  • Follows the same pattern used in efrit-do.el for OpenRouter support
  • Auto-detects response format based on choices array presence

Testing

  • Tested with OpenRouter using anthropic/claude-sonnet-4.5 model
  • Verified both text responses and tool calling work correctly

- Add efrit--get-model to select model based on efrit-api-backend
- Use efrit-common-build-headers for backend-specific HTTP headers
- Add efrit--build-request-data for Anthropic/OpenRouter format switching
- Add efrit--parse-openrouter-response for OpenAI-compatible responses
- Extract tools schema to efrit--tools-schema constant
- Add efrit--convert-tools-for-openrouter for tool format conversion

This enables efrit-chat to work with OpenRouter by setting:
  (setq efrit-api-backend 'openrouter)
  (setq efrit-model-openrouter "anthropic/claude-sonnet-4")

Maintains full backward compatibility with Anthropic backend.
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.

1 participant