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:
- Followed the Extended OpenAI Conversation intallation instructions: GitHub - jekalmin/extended_openai_conversation: Home Assistant custom component of conversation agent. It uses OpenAI to control your devices.
- Created an OpenRouter API key: API Keys | OpenRouter
- Modified Base URL to
https://openrouter.ai/api/v1
as per the quick start guide Quick Start | OpenRouter
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}}