Oryn Browser SDK · Developer alphaOpen source
Build for
local AI.
Add local AI to a website with one SDK. Your app requests work; Oryn manages permission, models and engines on the user’s computer.
SDK version and availability
The SDK documentation describes the 0.1.0 developer-alpha release candidate. The first public npm release is pending. A compatible Oryn Browser is required for model execution; installing the SDK alone does not provide a runtime.
The API may evolve before a stable release. Use localAI.sdkVersion for the SDK version and browserApiVersion from capabilities for the injected browser contract. Check feature flags and the returned session.taskProfile rather than inferring task support from a version number.
Current access and distribution status ↗ · Recorded model and device checks ↗
How Oryn works
- Your website asks. The SDK describes the task and model requirements.
- Oryn checks and prepares. The browser handles permission, model selection, downloads and device resources.
- The hardware does the work. Oryn’s engine runs the model locally and returns results to your app.
Before you start
The TypeScript SDK is framework-independent. Production websites use HTTPS; loopback development is supported. Importing the client is safe during server-side rendering, but perform feature work in the browser.
The SDK package is not published to the registry yet. The examples below describe the current developer-alpha API, not an available public package installation. Oryn Browser’s current target is Apple Silicon Macs.
Browser installation and availability ↗Stream text and handle the outcome
This complete function requests an eligible chat session, displays text deltas, handles terminal failure and cancellation, and releases the session. Your calling UI should catch errors, distinguish cancellation from failure, and offer the fallback appropriate to your product.
import {
createLocalAIClient,
invokeStream,
LocalAIError,
} from "@ocno/oryn-sdk";
// Call from Send; connect signal to your Cancel button.
export async function streamReply(
prompt: string,
appendText: (text: string) => void,
signal: AbortSignal,
): Promise<void> {
const localAI = createLocalAIClient();
const capabilities = await localAI.getCapabilities();
if (!capabilities.runtimeAvailable) {
throw new Error("Local AI is unavailable. Offer your fallback here.");
}
const session = await localAI.models.request({
role: "chat",
requirements: {
task: "text-generation",
inputModalities: ["text"],
outputModalities: ["text"],
capabilities: { chat: true, streaming: true },
},
}, { signal });
try {
for await (const event of invokeStream(localAI, {
sessionId: session.sessionId,
input: { messages: [{ role: "user", content: prompt }] },
}, { signal })) {
if (event.event === "job.output.delta" && event.data.channel === "text") {
appendText(String(event.data.delta));
} else if (event.event === "job.failed") {
throw new LocalAIError(event.data.error);
} else if (event.event === "job.cancelled") {
throw new LocalAIError({
code: "REQUEST_ABORTED",
message: "Generation was cancelled.",
});
}
}
} finally {
await localAI.models.releaseSession(session.sessionId);
}
}
Download this TypeScript recipe ↓
Both helpers subscribe before submitting a job. Breaking out of a stream only unsubscribes; it does not cancel the underlying job. Pass an AbortSignal or call cancel(jobId) to request cancellation.
API at a glance
| Method or helper | What it does |
|---|---|
getCapabilities() | Checks availability. Outside Oryn, runtimeAvailable is false. Detection does not grant permission or load models. |
models.request(request, options) | Requests an eligible model session. Inspect the returned resolution. |
invoke(request) | Submits a job. Subscribe first if using the low-level event API. |
subscribe(callback) | Receives your site’s job events. Returns an unsubscribe function. |
invokeStream(client, request, options) | Subscribes before submission and yields job events as an async iterable. |
invokeAndWait(client, request, options) | Waits for completion and returns the result. |
cancel(jobId) | Requests cancellation; interruption may happen at the next safe runner point. |
models.releaseSession(sessionId) | Releases the session when your feature is finished. |
Choose a result or a stream
Use invokeAndWait() for a final result. It rejects on job failure or cancellation. Use invokeStream() for incremental text or progress; it yields all events through the terminal event, so your app must inspect failure and cancellation.
| result.kind | Payload | Typical use |
|---|---|---|
structured | result.value: task-specific JSON | Transcript text, classification or other structured output |
artifact | result.artifact: output metadata | Display, read or save generated media through the artifact API |
multi | result.outputs: result envelopes | Consume each structured or media output |
Validate the expected task output before displaying it. Artifact IDs provide browser-managed access; release them after their final consumer has finished.
Ask for a task. Check the chosen model.
preferredModel expresses your preference. requirements describes the task, input/output types and needed features. certifiedModels lists alternatives your app has tested; it does not make them Oryn-certified.
Automatic substitution can be none, certified-only or compatible. The browser remains in charge of the permitted choice. Read session.resolution to show the actual model, compatibility, trust and whether a substitution occurred.
Support depends on the exact model files, version, task and device. An eligible unverified version needs a separate user trust decision. A website cannot bypass that decision or override blocked files, unsupported execution or resource limits.
Use artifacts for files and media
Artifacts are browser-managed handles for binary inputs and outputs. Use artifacts.create(file, { lifetime: "session" }) and pass the returned ID in the task’s input. The input field depends on the task; transcription can use audioArtifactId.
artifacts.getUrl(id)provides a URL for media display.artifacts.readBlob(id)reads an artifact into memory.artifacts.saveAs(id, options)opens the browser’s save UI.artifacts.release(id)releases access when you are finished.
IDs and URLs are restricted to the authorized site; they are not filesystem paths. Creating an artifact does not upload it. Any website upload is a separate action.
Turn expected failures into useful UI
| Code | Suggested application response |
|---|---|
RUNTIME_NOT_AVAILABLERUNTIME_STARTING | Explain availability or show your existing experience. |
USER_DENIEDPERMISSION_DENIED | Respect the decision and leave the feature idle. |
NO_EXECUTABLE_MODELMODEL_NOT_EXECUTABLE | Explain the unmet model or task requirement. |
MODEL_OUT_OF_MEMORYRESOURCE_REQUIREMENTS_UNSATISFIABLE | Offer a smaller compatible model or lower supported settings. |
JOB_QUEUE_FULL | Keep the input and let the person retry later. |
REQUEST_ABORTEDJOB_CANCELLED | Treat cancellation as an ordinary outcome. |
Branch on LocalAIError.code, and keep a general path for ordinary JavaScript errors. Release sessions in finally; release input and output artifacts when their consumers are finished.
What stays under the user’s control
Oryn owns permission, model choice, scheduling and trusted cancellation. Your site receives its own authorized results and job events. It cannot enumerate all installed models, inspect another site’s work, obtain local filesystem paths or access native engines directly.
Local processing does not define your website’s data practices. Explain any storage, uploads and cloud alternatives clearly. Keep private model inputs out of unrelated analytics or advertising flows.
Looking for concrete model and device checks? Browse the model evidence and evaluation guide.