Skip to content

fix(answer): update to getApiKeyAndHeaders API (pi-coding-agent 0.63+)#26

Closed
affsantos wants to merge 1 commit intomitsuhiko:mainfrom
affsantos:fix/answer-getApiKey-rename
Closed

fix(answer): update to getApiKeyAndHeaders API (pi-coding-agent 0.63+)#26
affsantos wants to merge 1 commit intomitsuhiko:mainfrom
affsantos:fix/answer-getApiKey-rename

Conversation

@affsantos
Copy link
Copy Markdown

@affsantos affsantos commented Mar 28, 2026

Problem

answer.ts extension crashes with:

Extension "command:answer" error: modelRegistry.getApiKey is not a function

Cause

ModelRegistry.getApiKey() was renamed to getApiKeyAndHeaders() in pi-coding-agent v0.63.0 (pi-mono@7a786d88, Mar 27 2026). The new method returns a ResolvedRequestAuth object instead of a plain string, supporting both API keys and request headers.

The pi-mono examples (qna.ts) were updated in the same commit, but this extension was not — since it lives in a separate repo.

Investigation trail

  1. The error modelRegistry.getApiKey is not a function pointed to the ModelRegistry API
  2. Checked pi-mono's model-registry.ts git history and found commit 7a786d88 (fix(coding-agent): resolve models.json auth per request closes #1835) which:
    • Renamed getApiKey(model)getApiKeyAndHeaders(model)
    • Changed the return type from Promise<string | undefined> to Promise<ResolvedRequestAuth> ({ ok: true, apiKey?, headers? } | { ok: false, error })
    • Updated all pi-mono examples including qna.ts (which this extension was originally based on)
  3. Confirmed: pi-mono checkout is at v0.62.0 (still has getApiKey), installed pi is v0.63.1 (has getApiKeyAndHeaders only)

Changes

  • Replace inline modelRegistry type with the actual ModelRegistry import from @mariozechner/pi-coding-agent
  • Use getApiKeyAndHeaders() which returns { ok, apiKey?, headers? } | { ok: false, error }
  • Pass headers alongside apiKey to complete() for proper auth (needed for providers with custom headers)
  • Add error handling when auth resolution fails

Notes

This is honestly my favourite pi extension — the interactive Q&A TUI for answering questions inline is brilliant. Just wanted to get it working again on 0.63+ 🙏

ModelRegistry.getApiKey() was renamed to getApiKeyAndHeaders() in
pi-coding-agent v0.63.0 (pi-mono commit 7a786d88). This broke the
answer extension with:

  Extension "command:answer" error: modelRegistry.getApiKey is not a function

Changes:
- Replace inline modelRegistry type with the actual ModelRegistry import
- Use getApiKeyAndHeaders() which returns ResolvedRequestAuth
- Pass headers alongside apiKey to complete() for proper auth
- Add error handling when auth resolution fails
Copy link
Copy Markdown

@marvelm marvelm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm running this patch on pi@0.63.2 - and it works correctly.

$ git -P diff HEAD

diff --git a/settings.json b/settings.json
index b160283..2aef010 100644
--- a/settings.json
+++ b/settings.json
@@ -1,5 +1,5 @@
 {
-  "lastChangelogVersion": "0.62.0",
+  "lastChangelogVersion": "0.63.2",
   "defaultProvider": "anthropic",
   "defaultModel": "claude-opus-4-6",
   "defaultThinkingLevel": "medium",
@@ -8,7 +8,7 @@
   ],
   "packages": [
     {
-      "source": "npm:mitsupi",
+      "source": "git:github.com/affsantos/agent-stuff@fix/answer-getApiKey-rename",
       "extensions": [
         "pi-extensions/answer.ts"
       ],

@marvelm
Copy link
Copy Markdown

marvelm commented Mar 29, 2026

Thank you @mitsuhiko for making this extension. It's what convinced me to switch to Pi

@mitsuhiko mitsuhiko closed this Mar 29, 2026
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.

3 participants