Add OpenAI-compatible AI provider (pi-native) - #4218
Open
georgestephanis wants to merge 2 commits into
Open
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
georgestephanis
marked this pull request as ready for review
July 15, 2026 19:31
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a first-class
openai-compatibleAI provider to the CLI so the Studio agent can run against a self- or independently-hosted open-weight model (vLLM, Apfel, LM Studio, Ollama, llama.cpp, …). Configure it with/openai-config;/modellists the endpoint's live models. This is the pi-native successor to #4206 — see the note below.Related issues
How AI was used in this PR
Built with Claude Opus 4.8 operating in VS Code. The author reviewed all changes. It was tested live against two local backends: Apfel (Apple's on-device FoundationModel, ~4k context) and a networked vLLM install running
qwen3.6-27b(64k context). The 64k model completes turns cleanly; the 4k model is deliberately included to document the minimum-context limit (see Testing).For anyone unfamiliar with Apfel: on a Mac it's a one-line
brew installthat exposes the OS's built-in Foundation Model over an OpenAI-compatible endpoint — no downloads or keys.Proposed Changes
GET /v1/models, so/modeloffers the server's real models (not Studio's built-in catalog), and each model's advertised context window (context_window/max_model_len) is read and handed to pi, which sizes its native compaction to the local model's real limit — important given the smaller context windows of consumer-GPU-hosted models.docs/design-docs/local-ai-providers.md.openAiCompatibleEndpoints) so multiple endpoints can be added later without a breaking migration; this PR wires up a single active endpoint.Testing Instructions
Prerequisites: a local OpenAI-compatible server. Any works (vLLM, LM Studio, Ollama, llama.cpp
--server, Apfel). Note the context-window caveat above — use a model with ≥16k context for a working chat; Apfel (4k) is only useful for observing the too-small-window error.Covers model-family/label fallbacks for unknown ids (
packages/common/ai/tests/models.test.ts), endpoint discovery field-name handling and graceful failure (apps/cli/ai/tests/openai-compatible.test.ts), and the provider list (apps/cli/ai/tests/auth.test.ts)./openai-config, enter the base URL and optional key. It lists the endpoint's models — pick one./modelre-lists the endpoint's models and lets you switch.qwen3.6-27b, 64k) completes turns cleanly (api=openai-completions,provider=openai, correct model id)./openai-configat Apfel (http://localhost:11435/v1, modelapple-foundationmodel).context_length_exceeded— expected: Studio's system prompt alone exceeds 4096 tokens. This documents the lower bound, it isn't a regression.wpcomandanthropic-api-keystill work exactly as before (the model-id type was widened, not changed for them).Pre-merge Checklist
🤖 Generated with Claude Code