build-with-ipa
Build or adapt browser apps to use the Inference Provider API (IPA, window.inference) for user-approved AI inference. Use for IPA chat, tools, hosted search, images, or bounded speech in an app. Not for implementing a browser extension or other IPA provider.
- License 许可
- MIT
- 最近更新
- 2026-11-12
- Stars
- ★ 8
- Forks
- 1
01 前言 Front Matter
- name
- build-with-ipa
- description
- Build or adapt browser apps to use the Inference Provider API (IPA, window.inference) for user-approved AI inference. Use for IPA chat, tools, hosted search, images, or bounded speech in an app. Not for implementing a browser extension or other IPA provider.
03 SKILL.md 正文
Build with IPA
IPA is an experimental browser API. The specification defines its contract; the ipa-tools README documents current helpers. Start with the chat demo for streaming, the translate demo for a final-only result, or the charts demo for page-executed tools. If this repository is available locally, read those files there instead. Check the relevant spec sections before implementing a feature; do not treat an example or a particular injector's extra methods as part of the standard.
Integrate into the app
- Fit IPA into the app's existing architecture and requested UX. IPA runs in a top-level browser page on HTTPS or loopback HTTP. It may be absent until a compatible injector is installed. Check
window.inference?.requestbefore enabling inference; explain how to install a compatible provider when it is missing. If late injection matters,ipa-toolsofferswaitForInference, but do not await it before first paint. - Use
window.inference.requestfor streaming. Formethod: "chat", iterate itsAsyncIterable:acceptedmeans the request is cleared to reach a provider;deltacarries display text;reasoning_deltais optional;donecontains the final message, model, and optional usage. A nonstreaming chat provider may yield onlyacceptedanddone. Iteration throws on failure, so handleerror.code(permission_denied,invalid_request,unavailable,provider_error,aborted) rather than relying oninstanceofacross extension worlds. Pass anAbortSignalwhen the UI offers cancellation. - For apps needing only the final result, use
completeorcreateInference().completefromipa-tools. For page-executed function tools, prefer itsrunToolshelper or implement the spec's multi-round loop.ipa-toolssupplies types and helpers; it does not injectwindow.inference, select a provider or model, or expose API keys. Keep provider credentials out of page code. - Gate optional request features using
window.inference.getFeatures?.() ?? {}.toolCalling,webSearch,imageInput, andimageOutputare independent. Do not send an unadvertised function tool, hosted search tool, image part, oroutput.images: true. Feature flags describe the injector's API surface, not a promise that the selected provider or model can fulfill a request.web_searchis hosted, so do not put it in page-side tool handlers. Requestoptionsare preferences, not model selection; checkfeatures.optionswhen deciding whether an option can have an effect. - Show a waiting state while permission resolves; the injector owns the permission prompt and the user chooses the provider and model there. An
acceptedchunk means permission has been resolved, including for an existing grant; it does not prove a prompt appeared. A tool result can be sent in a later round without another permission preview, so disclose what page tools may send before the first request. Treat image input and output and hosted search as distinct capabilities when presenting controls. - For bounded speech, first check
features.methods?.transcribe?.acceptedMediaorfeatures.methods?.synthesize. Use the samerequestwithmethod: "transcribe"andmedia(completed Blob, raw base64 with a type, or a page-resolved URL), ormethod: "synthesize"andtext. Transcription ends withdone.transcript; synthesis yields encodedaudio_deltabytes (MP3 by default; explicit WAV only whenmethods.synthesizeis an object whoseoutputMediaTypesincludesaudio/wav) and metadata-onlydone.audio. Legacysynthesize: truemeans MP3 only; create playback Blobs using the returned media type. KeepcompleteandrunToolschat-only. Never add method-named API functions, select provider/model/voice IDs from page code, upload live microphone streams, or autoplay output. Stop any page-owned recording before requesting separate IPA transcription approval. Read the speech examples; detect advertised method support before use.
Verify the integration
Exercise the relevant app flow in a secure browser context with a compatible injector such as Inference Bridge. Check the missing-injector state, permission denial, a successful final response (with and without streaming deltas), and cancellation if offered. For each optional feature used, check both advertised and unavailable states. A fallback backend is a separate app choice; do not present its output as IPA.
04 同仓库更多 Skills
ship-ipa-package
Prepare and verify npm releases of ipa-tools or ipa-prompt-api-fallback in this repository.
ship-ipa-package
Prepare and verify npm releases of ipa-tools or ipa-prompt-api-fallback in inference-provider-api. Use for shipping a named package, preparing a version bump, or checking publication and its demo update. Questions about whether a release is needed call for advice, not publication.
create-demo-og
Create or update matching Open Graph preview cards and social metadata for demo apps in the inference-provider-api repository. Use when adding an OG image or share preview to a demo under examples/, or refreshing one of these demo cards.