How to use OpenRouter in a Voice Assistant pipeline

Goal: Use Extended OpenAI Conversation integration from HACS to call OpenRouter API as part of a HA Voice Preview Edition voice assistant pipeline

Problem: After issuing a command to HA Voice Preview Edition, no action is performed or reply given. The following error appears in the log:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/assist_pipeline/pipeline.py", line 1093, in recognize_intent
    conversation_result = await conversation.async_converse(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<7 lines>...
    )
    ^
  File "/usr/src/homeassistant/homeassistant/components/conversation/agent_manager.py", line 110, in async_converse
    result = await method(conversation_input)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/extended_openai_conversation/__init__.py", line 199, in async_process
    query_response = await self.query(user_input, messages, exposed_entities, 0)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/extended_openai_conversation/__init__.py", line 376, in query
    if response.usage.total_tokens > context_threshold:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'total_tokens'

System config:
Core 2025.1.4
Supervisor 2024.12.3
Operating System 14.1
Frontend 20250109.2
Extended OpenAI Conversation 1.0.4

Background: I have read several posts from people saying that they have used Extended OpenAI Conversation integration to utilise LLMs other than OpenAI that support the OpenAI API

However, the posts do not provide detailed instructions on how to set up OpenRouter specifically

Setup:

Troubleshooting performed:

  • SUCCESS: Setup Extended OpenAI Conversation with it’s default config using OpenAI directly (confirmed integration and pipeline was working)
  • FAILED: changed the model to openai/gpt-3.5-turbo as per the examples in OpenRouter quick start
  • SUCCESS: Used the CURL script from OpenRouter quick start to confirm API key was correct. Observed that total_tokens was part of the response.
{"id":"gen-1737876138-WVmEX2JTI5jZo8Bm2XQ3","provider":"OpenAI","model":"openai/gpt-3.5-turbo","object":"chat.completion","created":1737876138,"choices":[{"logprobs":null,"finish_reason":"stop","native_finish_reason":"stop","index":0,"message":{"role":"assistant","content":"The meaning of life is a complex and deeply personal question that varies from person to person. Some may find meaning in religion, spirituality, relationships, personal growth, or contributing to society. Others may believe that life has no inherent meaning and that it is up to each individual to create their own purpose and meaning. Ultimately, the meaning of life is subjective and can be shaped by one's beliefs, values, experiences, and goals.","refusal":null}}],"system_fingerprint":null,"usage":{"prompt_tokens":14,"completion_tokens":87,"total_tokens":101}}

I get exactly the same problem, hopefully someone can point us in the right direction!

I use the OpenAI Compatible conversation extension and works like a charm with open router:

Link to the extension I use: GitHub - michelle-avery/openai-compatible-conversation: A copy of Home Assistant's built-in OpenAI Conversation Agent, with support for changing the base url

1 Like

Thankyou @fiberwings, works like a charm.

A dedicated Openrouter integration is now in Home Assistant 2025.8 !

1 Like

Now that there is a built in integration, which model does everyone think is the best for HA? Let’s figure free first and then the best model that supports the most functions.

I’m interested in Venice somewhat but I think I’m just going to start with the free version of ChatGPT to see how it goes. Maybe add in a few of them and test out different pipelines. Going to have to put a new GPU in my server now LOL. That’s not easy considering it’s a 1U rack mount!

Current preference Gemini 2.0 Flash and then Claude 3.5 Haiku. They are both low latency and seem to be able to interpret entities quite well.

Probably worth a new topic for this, I am also interested what everybody else is using for home control.