HKUDS/DeepTutor · warning · HTTPException
Client ID and API key are required.
Error message
Client ID and API key are required.
What it means
HTTP 400 raised when neither the request payload nor the stored credential overrides provide a complete Tencent IMA client_id/api_key pair. The route resolves credentials from payload plus defaults; if the pair is incomplete it refuses to call the IMA API.
Source
Thrown at deeptutor/api/routers/knowledge.py:1973
def _resolve_ima_credentials(client_id: str, api_key: str) -> ImaCredentials:
"""A request's credentials, falling back to the account-level pair.
A request that supplies only one half is not silently completed from the
account pair: mixing two accounts' halves would fail at IMA with a confusing
verdict.
"""
supplied = ImaCredentials(client_id=(client_id or "").strip(), api_key=(api_key or "").strip())
if supplied.client_id or supplied.api_key:
return supplied
return get_account_credentials()
@router.post("/list-ima", response_model=ListImaResponse)
async def list_ima_route(payload: ListImaRequest):
"""List IMA knowledge bases without storing or echoing credentials."""
credentials = _resolve_ima_credentials(payload.client_id, payload.api_key)
if not credentials.complete:
raise HTTPException(status_code=400, detail="Client ID and API key are required.")
client = ImaClient(
ImaConfig(
client_id=credentials.client_id,
api_key=credentials.api_key,
knowledge_base_id="",
)
)
try:
return await client.search_knowledge_bases(
query="",
cursor=payload.cursor.strip(),
limit=payload.limit,
)
except ImaAuthError:
raise HTTPException(status_code=401, detail="IMA rejected the supplied credentials.")
except ImaRateLimitError:
raise HTTPException(status_code=429, detail="IMA rate limit reached. Try again shortly.")View on GitHub (pinned to 3e82f13042)
Solutions
- Provide both client_id and api_key in the request payload
- Or configure complete IMA credentials in runtime settings so the resolver finds defaults
- Check for whitespace-only credential strings; they strip to empty and count as missing
Defensive patterns
Strategy: validation
Validate before calling
const creds = {clientId: clientId?.trim(), apiKey: apiKey?.trim()};
if (!creds.clientId || !creds.apiKey) throw new Error('IMA client_id and api_key required'); Prevention
- Configure IMA credentials once in runtime settings so every call is pre-authorized
When it happens
Trigger: POST /list-ima with empty client_id or api_key (or only one of them) and no complete saved defaults; _resolve_ima_credentials().complete is false.
Common situations: Forgetting to configure IMA credentials in settings before using the IMA browser, passing only api_key, or env-var names not picked up by the resolver.
Related errors
- Invalid folder path
- Validation failed for file '{original_filename}': {format_ex
- server_url is required.
- Both name and server_url are required.
- No fields to update
AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27).
Data as JSON: /api/errors/44eb67ba5e3132be.
Report an issue: GitHub.