JavaScript Quickstart
Run a script that asks Jan a question and prints its answer as it arrives.
You need Node.js 20+ and access to a model provider. No Git checkout, Jan Desktop, Rust toolchain or TypeScript build step is needed.
The ADK is a preview and is not published to npm yet: npm install @janhq/adk does not work.
Install the nightly package below instead. The runtime is a separate, prebuilt download.
Install the ADK and runtime
In a new directory, install the latest nightly ADK package:
mkdir jan-js-demo && cd jan-js-demonpm init -ynpm install "$(node -e "fetch('https://delta.jan.ai/adk-nightly/manifest.json').then(r => r.json()).then(m => console.log(m.packages.javascript.url))")"
The command looks up the current build and installs its versioned package URL, so
package.json pins that exact build. The download page (opens in a new tab)
shows the same command with the URL written out.
Install the jan runtime:
curl -fsSL https://delta.jan.ai/jan-cli/install-jan-agent.sh | bashexport PATH="$HOME/.local/bin:$PATH"
jan cli agent rpc --help
If you already have a current Jan runtime, skip its installation.
Connect a model
Sign in to Tokamak:
jan login
Or configure your own provider. Both the CLI and ADK use Jan's provider configuration. If you have already configured Jan, skip this step.
Save and run the script
Save this complete example as hello.mjs in jan-js-demo:
import { JanRuntime } from '@janhq/adk'const runtime = await JanRuntime.start()try { const session = await runtime.createSession({ ephemeral: true, builtins: false }) const turn = await session.prompt('Explain what a mutex is in one sentence.') for await (const event of turn) { if (event.type === 'token') process.stdout.write(event.text) } const result = await turn.result() if (result.stopReason === 'error') throw new Error(result.error) console.log(`\nFinished: ${result.stopReason}`)} finally { await runtime.close()}
node hello.mjs
The answer depends on your model. A successful run prints answer text followed by
Finished: completed.
What just happened?
start()launched the Jan runtime and checked its protocol version.createSession()created a conversation.ephemeral: trueavoids saving it;builtins: falsedisables built-in and external tool sources, so this first example only answers a question.prompt()started a turn. Eachtokenevent contains another piece of the answer.result()returned the final status.close()ended the process, even if the script failed.
Send another prompt on the same session to continue the conversation. To select a specific
configured model, add model: 'provider/model-id' to createSession().
TypeScript uses the same API; the installed package includes type declarations.
If it fails
| Problem | What to do |
|---|---|
Cannot find @janhq/adk | Run the npm install command above in jan-js-demo, and keep hello.mjs there. |
| The package download fails | No nightly is available right now. Use the source install. |
Cannot start jan | Add it to PATH, or pass its absolute path as JanRuntime.start({ bin: '/path/to/jan' }). |
Unknown rpc command or protocol mismatch | Run jan update, then retry startup. |
| No model, authentication error, or provider error | Run jan login or fix the provider configuration. A model override must name a model that provider serves. |
See Process & failures for error handling in an application.
Next: give the agent a function
The first script cannot act on your app. Add a host tool when you want it to read application data or perform an action.