Created
July 19, 2026 06:54
-
-
Save juanmackie/b986eadd936050e827fa79f2a4387562 to your computer and use it in GitHub Desktop.
NanoGPT Dynamic Provider Extension pi A [pi-coding-agent](https://github.com/earendil-works/pi-coding-agent) extension that dynamically registers [NanoGPT](https://nano-gpt.com) as an OpenAI-compatible model provider. On startup it fetches the current model catalog from the NanoGPT API and makes every available model selectable inside pi — no ma…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import type { ExtensionAPI } from "@mariozechner/pi-coding-agent"; | |
| /** | |
| * NanoGPT Dynamic Provider Extension | |
| * Fetches the latest models and pricing from nano-gpt.com | |
| */ | |
| export default async function (pi: ExtensionAPI) { | |
| try { | |
| // 1. Fetch live models | |
| const response = await fetch("https://nano-gpt.com/api/v1/models"); | |
| if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); | |
| const payload = (await response.json()) as { | |
| data: Array<{ | |
| id: string; | |
| name?: string; | |
| context_window?: number; | |
| max_tokens?: number; | |
| }>; | |
| }; | |
| // 2. Register NanoGPT as a dynamic provider | |
| pi.registerProvider("nanogpt", { | |
| baseUrl: "https://nano-gpt.com/api/v1", | |
| api: "openai-completions", | |
| apiKey: "nanogpt", // Uses the sk-nano key in your auth.json | |
| models: payload.data.map((model) => ({ | |
| id: model.id, | |
| name: `${model.name || model.id} (NanoGPT)`, | |
| // Guess reasoning based on common prefixes/suffixes | |
| reasoning: | |
| model.id.includes("thinking") || | |
| model.id.includes("reasoner") || | |
| model.id.includes("o1") || | |
| model.id.includes("o3") || | |
| model.id.includes("deepseek-r1") || | |
| model.id.includes("qwq"), | |
| input: ["text", "image"], | |
| contextWindow: model.context_window ?? 128000, | |
| maxTokens: model.max_tokens ?? 16384, | |
| cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } | |
| })), | |
| }); | |
| console.log(`[NanoGPT] Successfully registered ${payload.data.length} models.`); | |
| } catch (error) { | |
| console.error("[NanoGPT] Failed to fetch dynamic models:", error); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey,
if you query nano-gpt.com/api/v1/models?detailed=true you get a lot of the info you currently emulate ;-).