Created
July 19, 2026 07:04
-
-
Save juanmackie/e9e3e8739e6b92e54dc38ad8046a6883 to your computer and use it in GitHub Desktop.
A [pi-coding-agent](https://github.com/earendil-works/pi-coding-agent) extension that dynamically registers [Croft AI](https://crof.ai) as an OpenAI-compatible model provider. On startup it fetches the current model catalog from the Croft AI API and makes every available model selectable inside pi — no manual model list to maintain
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"; | |
| /** | |
| * Croft AI Dynamic Provider Extension | |
| * Fetches the latest models from crof.ai | |
| */ | |
| export default async function (pi: ExtensionAPI) { | |
| try { | |
| // 1. Fetch live models | |
| const response = await fetch("https://crof.ai/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 crofAI as a dynamic provider | |
| pi.registerProvider("crofai", { | |
| baseUrl: "https://crof.ai/v1", | |
| api: "openai-completions", | |
| apiKey: "crofai", // Refers to the "crofai" key in your auth.json | |
| authHeader: true, | |
| models: payload.data.map((model) => ({ | |
| id: model.id, | |
| name: `${model.name || model.id} (Croft AI)`, | |
| // 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(`[Croft AI] Successfully registered ${payload.data.length} models.`); | |
| } catch (error) { | |
| console.error("[Croft AI] Failed to fetch dynamic models:", error); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment