API Key Error in Title Generation | Generated by AI
Question: Why does “Auxiliary title generation failed: HTTP 401: Invalid API Key” occur?
Answer:
I traced the full code path. Here’s what’s happening:
The Flow
- After the first user/assistant exchange,
maybe_auto_title()fires a background thread (agent/title_generator.py) - It calls
call_llm(task="title_generation", main_runtime=main_runtime)in agent/auxiliary_client.py _resolve_task_provider_model()reads configauxiliary.title_generation— yours is set toprovider: autowith empty model/base_url/api_key_resolve_auto()picks up your main provider (xiaomi) + model (mimo-v2.5-pro) + base_url (https://token-plan-cn.xiaomimimo.com/v1)- It creates an OpenAI client hitting
XIAOMI_API_KEYfrom your.hermes/.env - If that key is invalid/expired → HTTP 401 from the Xiaomi API
Why Main Chat Works But Title Gen Fails (or vice versa)
The key resolution paths differ slightly:
- Main chat: Creates an OpenAI client at agent init time with the API key from the credential pool/env
- Title gen: Creates a separate cached client via
resolve_provider_client()in a background thread, resolving the API key fresh fromXIAOMI_API_KEYenv var or the credential pool
If the key was recently rotated, expired, or the credential pool had a stale entry, one path might use a cached valid client while the other resolves a fresh (now-invalid) key.
Evidence From Your Logs
From errors.log, on 2026-05-29 both paths were failing:
10:13:25 API call failed ... provider=xiaomi ... summary=HTTP 401: Invalid API Key
10:13:55 API call failed ... provider=xiaomi ... summary=HTTP 401: Invalid API Key
10:14:13 API call failed ... provider=xiaomi ... summary=HTTP 401: Invalid API Key
These were main conversation loop calls, not just title gen. Your XIAOMI_API_KEY was invalid at that time. After you updated the key, everything recovered — the recent logs (June 14-21) show successful title_generation calls.
If It’s Happening Right Now
The 401 means your XIAOMI_API_KEY in ~/.hermes/.env is invalid. Verify:
# Check if the key works directly
curl -s https://token-plan-cn.xiaomimimo.com/v1/models \
-H "Authorization: Bearer *** | head -5
If it returns 401, regenerate the key at https://platform.xiaomimimo.com and update ~/.hermes/.env.
To Suppress the Warning (if key is fine and it’s a transient blip)
You can configure title_generation to use a different provider:
auxiliary:
title_generation:
provider: xiaomi
model: mimo-v2.5
timeout: 30
Or disable auto-titling entirely by setting auxiliary.title_generation.provider: none in config.yaml.