pi-provider-freellmapi

extension

Register the FreeLLM API gateway (freeapi.n.cofire.cn) as an OpenAI-compatible provider in pi, with automatic model discovery and tools for embeddings, image/video generation, speech, and transcription

by — · v1.0.7 · published 2w ago

$ pi install npm:pi-provider-freellmapi
downloads/mo
955
stars
—
last push
—
open issues
—

Signals

license: MITtestspi manifest: missinginstall size: —deps: 0peer deps: 0

Download trend

No downloads in the last 12 weeks.

README

pi-provider-freellmapi

A pi extension that registers the FreeLLM API gateway (freeapi.n.cofire.cn) as three pi providers — openai-completions, openai-responses, and anthropic-messages — with automatic model discovery and custom tools for non-chat endpoints.

It only exposes models your API key can actually use (the gateway reports ~250 models, but most are available: false for a free key — this extension filters those out), and it reads each model's real context window and reasoning/vision capabilities.

Install

pi install npm:pi-provider-freellmapi

Providers

The extension registers three pi providers sharing the same model list from the gateway so you can pick whichever API shape suits your use case:

ProviderAPI typeEndpoint
freellmapiopenai-completions/v1/chat/completions
freellmapi-responsesopenai-responses/v1/responses
freellmapi-anthropicanthropic-messages/v1/messages

Select a provider in the TUI with /model, or from the CLI:

pi --provider freellmapi --model auto
pi --provider freellmapi-responses --model auto
pi --provider freellmapi-anthropic --model auto

Disable extra providers via the endpoints config (see below).

Configure

Copy the example config to ~/.pi/agent/freellmapi.json and fill in your key:

cp "$(pi config-dir 2>/dev/null || echo ~/.pi/agent)/freellmapi.json" freellmapi.example.json
# or just:
mkdir -p ~/.pi/agent
cp freellmapi.example.json ~/.pi/agent/freellmapi.json
{
  "name": "freellmapi",
  "label": "FreeLLM API",
  "baseUrl": "https://freeapi.n.cofire.cn",
  "apiKey": "$FREELLM_API_KEY",
  "fetchModels": true,
  "contextWindow": 131072,
  "maxTokens": 16384,
  "compat": { "supportsDeveloperRole": false },
  "endpoints": {
    "embeddings":     { "enabled": true, "model": "auto" },
    "images":         { "enabled": true, "model": "auto" },
    "videos":         { "enabled": true, "model": "inkling" },
    "speech":         { "enabled": true, "model": "auto" },
    "transcriptions": { "enabled": true, "model": "whisper-1" },
    "responses":      { "enabled": true },
    "anthropic":      { "enabled": true }
  }
}

The apiKey supports pi's value syntax: a literal, $ENV_VAR, ${ENV_VAR}, or !command. You can also skip the config file entirely and set either env var.

Environment variables (fallback chain, config file wins):

VariablePurpose
FREELLM_API_KEYAPI key
FREELLM_API_BASE_URLOverride the base URL (default: https://freeapi.n.cofire.cn)
PI_FREELLMAPI_CONFIGPath to config JSON (default: ~/.pi/agent/freellmapi.json)
  • Set "fetchModels": false to use only the static models list.
  • Set "endpoints": { "responses": false } to disable a provider/tool.

Endpoint tools

In addition to the chat providers, the extension registers custom tools that wrap the gateway's other OpenAI-compatible endpoints. They are enabled by default; set "enabled": false ("endpoints": { "images": false }) or set a default model per endpoint to customize them.

ToolEndpointWhat it does
freellm_embedPOST /embeddingsGenerates embeddings; writes JSON to a file
freellm_imagePOST /images/generationsGenerates image(s), returned inline
freellm_videoPOST /videos/generationsGenerates a video, polls the task, downloads the file
freellm_speechPOST /audio/speechSynthesizes speech, writes audio to a file
freellm_transcribePOST /audio/transcriptionsTranscribes a local path or URL, returns text

Each tool accepts an optional model argument. When omitted, the extension picks a default from (in priority order): the endpoint's model config, model ids discovered from {baseUrl}/models matching that endpoint, or a conventional OpenAI id (e.g. auto for embeddings/images/speech, inkling, whisper-1). If the gateway rejects a default, set the endpoint's model in config.

Files written by the tools land in the session working directory with freellm-* names, or an outputFile path you pass to the tool.

Config reference

FieldDefaultDescription
namefreellmapiProvider id (--provider <name>)
labelFreeLLM APIDisplay label shown in /model
baseUrlhttps://freeapi.n.cofire.cnBase URL (auto-appends /v1)
apiKey$FREELLM_API_KEYAPI key (literal / env / command)
fetchModelstrueDiscover models from {baseUrl}/models
contextWindow131072Fallback context window per model
maxTokens16384Fallback max output tokens
compat{"supportsDeveloperRole":false}Provider compatibility flags
models[]Static models (override discovered models by id)
headers{}Extra headers merged into every tool request
endpointsall enabledPer-endpoint enabled flag and default model

License

MIT