Skip to content

Run Studio: embedded, local binary or hosted

View as Markdown

Studio is weft’s Inspector: a web UI, a JSON API, a live stream and an OTLP receiver over one recorded database, served as one http.Handler with the UI embedded. Run it one of three ways: embedded in your Go app (setup A), as the weft studio binary for apps in any language (setup B), or hosted behind a token (setup C).

For a Go app, setup A is two statements beside your own routes:

studio/main.go
defer otel.Install(otel.Local(""))() // ./.weft/weft.db (or $WEFT_DB), content on
mux := http.NewServeMux()
mux.Handle("/studio/", http.StripPrefix("/studio",
studio.Handler(studio.DB(otel.LocalDB()))))

studio/main.go on GitHub

Open http://127.0.0.1:8080/studio/ (or wherever your mux listens) and the runs list shows every run the app records.

weft Studio's runs list: each run's status, prompt and id, agent, steps, tokens, cost, start and duration, newest first, with a checkbox per row to pick runs to compareweft Studio's runs list: each run's status, prompt and id, agent, steps, tokens, cost, start and duration, newest first, with a checkbox per row to pick runs to compare
The runs list, the page Studio opens on.

All three serve the same UI and API. They differ in who runs the server and what guards the API.

SetupWho runs itDatabaseGuard on /apiStart it with
A · embeddedyour Go appthe handle the recorder writes (otel.LocalDB())a loopback Host, and no cross-origin writesstudio.Handler or studio.New
B · local binaryweft studio or weft devsqlite://path or clickhouse://…the dev tokenweft studio
C · hostedyour serverany obsdb.DBstudio.Token, and per-conversation panel tokensstudio.New(…, studio.Token(tok))

Setup A is live with no network: writes go to the recorder’s database handle, whose in-process hub feeds /api/live. Setup B receives OTLP over HTTP from any process on the same machine, so a Python or TypeScript app shows up beside your Go services. A non-Go app gets its traces, the runs derived from them and the devtools panel; the playground, breakpoints and approvals need a runtime link, which is Go only today.

The receiver is OTLP/HTTP only: POST /v1/traces and POST /v1/logs at the root, protobuf or JSON, with no gRPC and no metrics. Give an exporter the bare origin, and it adds /v1/traces and /v1/logs itself. Python’s exporter defaults to gRPC and needs OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf; the JavaScript one defaults to HTTP. A stock invoke_agent span makes a run, and gen_ai.conversation.id groups runs into a session (Inspect agents written in other languages). Setup C is setup A’s handler behind a bearer token, for a Studio other people reach.

studio.DB(otel.LocalDB()) serves the same obsdb.DB handle the local sink writes. That shared handle is what makes setup A live: its hub publishes each write, and the live stream follows it.

Name the sink. otel.Install(otel.Local("")) keeps the local sink even when the environment adds a destination (WEFT_STUDIO_URL, OTEL_EXPORTER_OTLP_ENDPOINT, or a running weft studio’s discovery file). A bare otel.Install() adds the sink only when the environment names no destination; otherwise otel.LocalDB() is nil, and studio.DB(nil) panics when the server is built. Your first agent uses the same two lines.

The other ways to point Studio at a database:

  • studio.Open(path) opens an obsdb SQLite file, creating it when missing. It panics when the file cannot be opened.
  • With neither DB nor Open, Studio opens $WEFT_DB, else ./.weft/weft.db. That second handle on the file reads history only: no live lane.

studio.Handler(opts...) is studio.New(opts...).Handler(). Use studio.New when you need to close the server or reach the playground’s runtime link:

studio/main.go
srv := studio.New(
studio.DB(db), // the recorder's handle: history and the live lane
studio.Retain(30*24*time.Hour), // delete runs last seen over 30 days ago
studio.Pricing(studio.PricingTable{ // USD per 1M tokens, replaces the shipped table
Dated: "2026-10-10",
Models: []studio.ModelPrice{{Provider: "acme", ModelGlob: "acme-*", Input: 1, Output: 4}},
}),
studio.Playground(true), // the playground routes and the runtime link
)
defer srv.Close() // stops the sweeper and the runtime link; a DB passed with DB stays open
mux := http.NewServeMux()
mux.Handle("/studio/", http.StripPrefix("/studio", srv.Handler()))

studio/main.go on GitHub

Server.Close stops Retain’s sweeper, shuts down the playground’s runtime link server when Playground(true) built one, and closes the database only when New opened it (Open, or the default path). A handle you passed with DB stays yours. Server.Runtime is the runtime link server that runtime.Local takes; it is nil without Playground(true).

Every option of studio.New is an Option:

OptionDefaultEffect
DB(db)$WEFT_DB, else ./.weft/weft.dbThe database to serve. A nil db panics in New
Open(path)—DB(sqlite.Open(path)), opened in New
Base(path)/studio/The path Studio is mounted at, with both slashes; written into the page’s <base href>
Title(s)weft studioThe page title
Manifest(json)noneweft.json bytes for the agent and tool cards. Without one (and no runtime registering one) /api/manifest answers 404 and the Agents page is hidden, unless the playground is on: then Agents shows “No agents to show” until a runtime registers
Live(hub)the DB’s own hub, else one fed by ingestWhere /api/live reads frames
NoIngest()ingest onTurns /v1/traces and /v1/logs off: a read-only Studio
IngestToken(tok)loopback peers onlyRequires Authorization: Bearer <tok> on OTLP ingest; once set, every ingest POST needs it, loopback included
Token(tok)noneWalls the JSON API with a bearer token; keys the panel tokens
AllowOrigins(origins...)none without a Token; with one, localhost and 127.0.0.1 on any portCORS origins; without a Token, also the extra Hosts the API answers
Capabilities(names...)noneCapability names a hosting wrapper adds to /api/meta
Playground(on)offThe playground routes and the runtime link server
Retain(d)offDeletes runs not running and last seen more than d ago, once at New and then every min(d/10, 1h) (at least a minute apart). d must be at least 1h: New panics below it, since a run silent for 30 s reads interrupted and would be swept
DiscoveryFile(path)unsetSince 0.20.0: the discovery file the hosting command writes for this server (weft studio and weft dev set it). /api/meta serves it as discovery_file, under db.path’s rule, while the file names this process. An embedded Studio writes no such file and leaves it unset
OffReason(capability, why)the Go option’s wordsSince 0.20.0: your words for why capabilities_off says a capability is off. They replace the reason of every capability off for the same cause. weft studio --no-playground says “weft studio was started with —no-playground: drop the flag to turn the playground on”. Words only; naming a capability that is not an optional one panics in New. ExampleOffReason and ExampleDiscoveryFile show both
Pricing(table)$WEFT_PRICING, else the shipped tableThe table usage is priced with, replacing the default whole. A WEFT_PRICING file that does not load makes New panic, naming the path and the field

/api/meta reports what the server does: its capabilities list is computed from the route groups it registered (live, ingest, search, playground and others), its retention from Retain, its pricing.source (default, file or option) from Pricing. The UI shows a screen only when its capability is listed. Keep and delete recorded runs covers Retain; See what a run cost covers pricing; Connect your app to Studio’s playground covers Playground(true).

Without a Token, the whole /api tree answers only a request whose Host is loopback: localhost, *.localhost, 127.0.0.0/8 or [::1], any port. A DNS-rebinding page (http://evil.example:7331 resolving to 127.0.0.1) gets a 403 instead of your transcripts. X-Forwarded-Host and Forwarded are never trusted; behind a proxy, the Host it forwards is the one checked.

Setup A also refuses a cross-origin write: an unsafe method (anything but GET, HEAD or OPTIONS) whose Origin is not Studio’s own and not an AllowOrigins entry, or one with no Origin but Sec-Fetch-Site: cross-site. The answer is a 403 that starts cross-origin write refused (setup A). Same-origin pages and clients that send neither header (curl, the runtime link) go through.

An app served on a real hostname without a token lists its origin, whose host:port must equal the request’s Host:

studio/main.go
mux := http.NewServeMux()
mux.Handle("/studio/", http.StripPrefix("/studio", studio.Handler(
studio.DB(db),
studio.AllowOrigins("http://myapp.internal:8080"),
)))

studio/main.go on GitHub

The UI shell and /panel.js carry no data and are served to any Host. /panel.js is the devtools panel, which your own pages load from Studio (Install the devtools panel). The same bytes are packaged for npm as @weftgo/devtools (make devtools-npm in weft’s repository), but the package is not published to the registry.

weft’s examples/studio-local is setup A whole: otel.Install(otel.Local(""), otel.Slog()), studio.New(studio.DB(otel.LocalDB()), studio.Playground(true)) mounted under /studio/, a thread session whose turns appear live, the devtools panel on its landing page, and runtime.Install(runtime.Local(srv), …) so the playground drives its agent. It runs offline on a deterministic model:

Terminal window
go run ./examples/studio-local

Run it from a clone of weft at v0.20.2. It listens on 127.0.0.1:7331 (on 127.0.0.1:8080 when WEFT_STUDIO_URL or a running weft studio’s discovery file names a Studio, which then holds 7331) and serves Studio at /studio/; curl -s -XPOST localhost:7331/run -d 'where is order 42?' starts a turn. Its agent’s PrepareStep trims a paragraph from the system prompt after step 0, which the run page’s Request pane shows as “changed by PrepareStep”.

Setup B is the weft command (Install the weft command). With no flags it serves the UI, OTLP ingest, the playground and a dev token on 127.0.0.1:7331, over $WEFT_DB or ./.weft/weft.db:

Terminal window
weft studio
weft studio --db sqlite://runs.db --retain 720h
weft studio --db clickhouse://user:pass@host:9000/db --addr 127.0.0.1:7400

The binary serves the UI at its root, so the runs list is http://127.0.0.1:7331/runs. Its flags:

FlagEnv varDefaultEffect
--addrWEFT_STUDIO_ADDR127.0.0.1:7331Listen address; set, it pins: a busy address is an error
--dbWEFT_DB, a bare SQLite path./.weft/weft.dbsqlite://path or clickhouse://user:pass@host:9000/db. Only the flag takes a URL
--tokenWEFT_STUDIO_TOKENthe database’s <db>.tokenThe API token
--rotate-token——Writes a new <db>.token before serving
--manifestWEFT_MANIFESTthe nearest weft.json upwardThe manifest for the agent and tool cards
--open—on when stdout is a terminalOpens the browser with the token in the URL fragment
--no-playground—playground onTurns the playground off
--retainWEFT_RETAINoffRetention, a Go duration of at least 1h; less (--retain 30m) is a usage error, exit 2
--pricingWEFT_PRICINGthe shipped tableA pricing file that replaces the table; a file that does not load is exit 1, naming the path and the field
--log-levelWEFT_LOG_LEVELinfodebug, info, warn or error
--log-formatWEFT_LOG_FORMATtext when a level is set, otherwise Go’s plain log linetext or json

The dev token. It is stable per database: weft studio keeps it in <db>.token beside the SQLite file, mode 0600, and never prints it. --open hands it to the browser in the URL fragment, which never reaches a server; any other browser asks for it once (“This Studio needs its API token”) and keeps it. A database with no file gets a generated token, printed at start.

The discovery file. Once the listener is bound, weft studio writes studio.json (url, token, db, pid, start time, version; mode 0600) in the first of ./.weft/ when it exists, $XDG_RUNTIME_DIR/weft/, or the user cache directory, and removes it on exit. A Go app’s otel.Install() reads it when WEFT_STUDIO_URL is unset and the pipeline names no otel.Studio(…) or otel.Local, and exports to that Studio with no configuration. runtime.Install() reads it too, but opens its link only under WEFT_ENV=dev or runtime.Enabled(true). A file is trusted only when its URL is loopback, its pid is alive, it is under 24 hours old and, on unix, it is 0600 and yours. WEFT_STUDIO_URL always wins; WEFT_DISCOVERY=off turns the read off and, since 0.18.0, the write: weft studio then writes no file and says so in one start line (Environment variables).

One Studio per database file. Since 0.20.0 weft studio takes <db>.lock, an exclusive OS lock, before it probes any port, and holds it while it serves. The kernel releases it when the process ends, however it ends. A second weft studio on the same SQLite file is refused with exit 1, before it opens the database or a listener. It prints on stderr:

weft: studio already running at http://127.0.0.1:7331 (pid 1234) on /home/you/.weft/weft.db: one Studio per database file — sign in to it with `weft open --with-token`, or stop it first

weft dev reuses the running Studio instead. A ClickHouse database is a shared server and takes no lock.

The port. Anything else on 7331 moves Studio to the next free port in 7331–7340, said in one line. That covers another program, a Studio on another database, or one whose meta this token cannot read. --addr pins the address instead.

An app in another language exports OTLP over HTTP to the same port; Studio ingests from loopback without a token. The binary has no ingest-token flag, so setup B takes OTLP from this machine only. Python’s OTLP exporter defaults to gRPC, so ask for HTTP:

Terminal window
OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:7331 OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf python app.py

weft dev runs Studio in-process and your app beside it, restarting the app on a .go save; it takes the same flags plus --no-watch and --watch dir:

Terminal window
weft dev
weft dev -- go run ./cmd/app

Develop with weft dev covers it, and Inspect agents written in other languages what Studio derives from a non-weft app’s spans.

Setup C is the same handler with studio.Token. Every /api request then needs Authorization: Bearer <token>, and the Host no longer matters:

studio/main.go
mux := http.NewServeMux()
mux.Handle("/studio/", http.StripPrefix("/studio", studio.Handler(
studio.DB(db),
studio.Token(apiToken), // every /api route: Authorization: Bearer <apiToken>
studio.IngestToken(ingestToken), // /v1/traces and /v1/logs: Authorization: Bearer <ingestToken>
)))

studio/main.go on GitHub

A token in the URL (?token=) is refused on every /api route, in every setup: the answer is a 401 that starts a token in the URL is never accepted. A browser’s live stream opens with a short-lived signature instead (Watch runs live).

OTLP ingest has its own rule. Without IngestToken it answers loopback peers only, and refuses even those when the request carries Forwarded, X-Forwarded-For or X-Real-IP, or a browser Origin that is not allowed; so a Studio bound wide refuses remote exporters until you set one. Once it is set, every ingest request needs Authorization: Bearer <ingestToken>, loopback included. Your backend mints per-conversation panel tokens through POST /api/panel-tokens for the devtools panel; Secure Studio covers them, TLS and the proxy rules.

Every response carries an X-Request-Id (the client’s, else a generated one; Server.ServeHTTP), and a 5xx or a refused ingest batch is one line on slog.Default naming it (refused-ingest lines at most one a minute per remote, route and status; 5xx lines are never limited) (Operate Studio).

To see Studio with data before you record any, run weft’s studio/examples/basic. It records a tool-call run, a subagent run and a failing run into <dir>/dev.db (default .weft), then serves Studio on 127.0.0.1:7331:

Terminal window
go run github.com/weftgo/weft/studio/examples/basic@v0.20.2
studio: http://127.0.0.1:7331/studio/

-serve skips recording and only serves; -addr picks the address. It writes obsdb batches directly, where a real app records the same rows through weft/otel.

github.com/weftgo/weft/studio is a package of the framework module: go get github.com/weftgo/weft brings it, at the same version as every other layer. studio.Version is that module version, reported as /api/meta’s studio_version. The package imports core and obsdb (its SQLite backend among them) and never the ClickHouse backend: within weft, only the weft binary (cmd/weft) imports obsdb/clickhouse. A setup-C server of your own may import it too.

The example’s main.go records one scripted run and serves Studio in setup A; its other functions are the studio.New, token and hostname variants above:

studio/main.go
// Command studio is the "Run Studio" page's program: setup A, Studio
// embedded beside the app over the recorder's own database handle, plus the
// studio.New form with its options, a token-walled Studio and an app served
// on a real hostname.
//
// main runs setup A: it records one run of a scripted support agent, then
// serves Studio at http://127.0.0.1:8080/studio/. The other functions are
// the page's variants; main_test.go runs each of them offline.
package main
import (
"context"
"fmt"
"log"
"net/http"
"time"
"github.com/weftgo/weft"
"github.com/weftgo/weft/obsdb"
"github.com/weftgo/weft/otel"
"github.com/weftgo/weft/studio"
"github.com/weftgo/weft/wefttest"
)
// LookupInput is lookup_order's input.
type LookupInput struct {
OrderID string `json:"order_id" jsonschema:"the order to look up"`
}
// newAgent is a support agent with one tool, on a scripted model so the
// program runs offline.
func newAgent() *weft.Agent {
lookup := weft.Tool("lookup_order", "Look up an order by ID.",
func(ctx context.Context, in LookupInput) (string, error) {
return "order " + in.OrderID + ": shipped", nil
})
model := wefttest.Script(
wefttest.ToolCalls(wefttest.Call{ID: "c1", Name: "lookup_order", Args: `{"order_id":"1234"}`}),
wefttest.Say("Order 1234 has shipped."),
)
return weft.New(model, weft.Name("support-bot"), lookup)
}
// run is setup A: record every run into the local sink and serve Studio
// over the same handle, so the UI reads what the runs wrote, live.
func run(ctx context.Context, serve func(http.Handler) error) error {
defer otel.Install(otel.Local(""))() // ./.weft/weft.db (or $WEFT_DB), content on
mux := http.NewServeMux()
mux.Handle("/studio/", http.StripPrefix("/studio",
studio.Handler(studio.DB(otel.LocalDB()))))
if _, err := newAgent().Generate(ctx, weft.Prompt("Where is order 1234?")); err != nil {
return err
}
return serve(mux)
}
// serveServer is the studio.New form: options, then Handler, then Close.
func serveServer(db obsdb.DB, serve func(http.Handler) error) error {
srv := studio.New(
studio.DB(db), // the recorder's handle: history and the live lane
studio.Retain(30*24*time.Hour), // delete runs last seen over 30 days ago
studio.Pricing(studio.PricingTable{ // USD per 1M tokens, replaces the shipped table
Dated: "2026-10-10",
Models: []studio.ModelPrice{{Provider: "acme", ModelGlob: "acme-*", Input: 1, Output: 4}},
}),
studio.Playground(true), // the playground routes and the runtime link
)
defer srv.Close() // stops the sweeper and the runtime link; a DB passed with DB stays open
mux := http.NewServeMux()
mux.Handle("/studio/", http.StripPrefix("/studio", srv.Handler()))
return serve(mux)
}
// hosted is a Studio that may listen beyond loopback: a bearer token walls
// the API, and OTLP ingest takes its own token.
func hosted(db obsdb.DB, apiToken, ingestToken string) http.Handler {
mux := http.NewServeMux()
mux.Handle("/studio/", http.StripPrefix("/studio", studio.Handler(
studio.DB(db),
studio.Token(apiToken), // every /api route: Authorization: Bearer <apiToken>
studio.IngestToken(ingestToken), // /v1/traces and /v1/logs: Authorization: Bearer <ingestToken>
)))
return mux
}
// onHostname is setup A for an app served on a real hostname without a
// token: the origin is listed, so its Host is answered besides loopback.
func onHostname(db obsdb.DB) http.Handler {
mux := http.NewServeMux()
mux.Handle("/studio/", http.StripPrefix("/studio", studio.Handler(
studio.DB(db),
studio.AllowOrigins("http://myapp.internal:8080"),
)))
return mux
}
func main() {
serve := func(h http.Handler) error {
fmt.Println("Studio: http://127.0.0.1:8080/studio/")
return http.ListenAndServe("127.0.0.1:8080", h)
}
if err := run(context.Background(), serve); err != nil {
log.Fatal(err)
}
}

View studio/main.go on GitHub

View on GitHub · run it from docs-site/examples:

Terminal window
go run ./studio
go test ./studio
Studio: http://127.0.0.1:8080/studio/

The tests in main_test.go check that /studio/api/meta answers and lists the run, that a cross-origin POST and a foreign Host are refused under setup A, that a Token walls the API and refuses ?token=, and that Retain, Pricing and Playground(true) show in /api/meta. The package’s own examples: ExampleHandler mounts studio.Handler(studio.DB(db)) under /studio/ over a SQLite handle and reads /studio/api/meta (200); ExampleServer builds studio.New(studio.Open(path), studio.NoIngest()), takes its Handler(), shows Runtime() nil without Playground(true), and closes it.

  • Name the local sink when you embed Studio. otel.Install() alone writes no local sink when the environment names a destination, and studio.DB(nil) panics: studio: New called with a nil DB. (Source: otel/pipeline.go:332-351; studio/studio.go:255)
  • Pass the recorder’s handle, not a path. studio.Open or the default path opens a second handle: history works, live does not. (Source: studio.DB godoc)
  • Build a Studio with Retain or Playground(true) through New, and close it. Nothing can close the server Handler builds; its sweeper stops only when the database closes. (Source: studio.Handler and studio.Retain godoc)
  • Set a Token before Studio listens beyond loopback. Without one, the API’s only guard is the loopback Host; AllowOrigins widens it to the hosts you list. (Source: studio.Token godoc; studio/auth.go:246-303; the example’s TestTokenWallsAPI)
  • Configure ClickHouse with --db, not WEFT_DB. WEFT_DB is a bare SQLite path, so a container that sets WEFT_DB='clickhouse://…' gets an empty SQLite Studio under a directory named after the URL, password included, with no error (weft CLI reference). (Source: cmd/weft/main.go:886-906, 925-933; observed with the v0.20.2 binary)
  • Behind a proxy that rewrites Host (Vite’s changeOrigin: true), list the front origin in AllowOrigins. Setup A compares the Origin’s host:port with the Host. (Source: studio/README.md:38-45)

Symbols used: studio.Handler · studio.New · studio.Server · Server.Handler · Server.Close · Server.Runtime · Server.ServeHTTP · studio.Option · studio.DB · studio.Open · studio.Base · studio.Title · studio.Manifest · studio.Live · studio.NoIngest · studio.IngestToken · studio.Token · studio.AllowOrigins · studio.Capabilities · studio.Playground · studio.Retain · studio.Pricing · studio.PricingTable · studio.ModelPrice · studio.Version · otel.Install · otel.Local · otel.LocalDB · obsdb.DB · weft.Tool · weft.New · weft.Name · weft.Prompt · Agent.Generate · wefttest.Script