Environment variables
weft reads its environment in a few places only: weft/otel (destinations and the local sink), weft/runtime (the playground link), weft/studio, the weft command, and one switch in the core. The provider adapters leave credentials to their vendor SDKs, which read their own variables. Each row below names the variable, the code that reads it, what it changes, its default, and the page that explains it. Where a flag or an option sets the same thing, it wins over the variable. The exception is weft/otel’s environment destinations: they are added beside the destinations you name in code, and one at the same URL as an explicit destination is dropped.
Recording and discovery
Section titled “Recording and discovery”Read by an app that calls otel.Install or runtime.Install. otel.NoEnv() turns off the destination variables and the discovery file for the pipeline, and makes WEFT_ENV count as unset (RawBodies and Blocking are refused); WEFT_DB and the resource variables are still read.
| Variable | Read by | Effect | Default | Explained in |
|---|---|---|---|---|
WEFT_STUDIO_URL | otel/env.go:39, internal/discovery/discovery.go:354, cmd/weft/resolve.go:60, internal/doctor/doctor.go:400 | Adds a Studio destination (OTLP/HTTP, content on) at this URL; a value without a scheme gets https://. When set, the discovery file is not read. Also the default --url of weft doctor, runs, open, export and mcp; weft doctor reports its value in this shell as a runtime hint | Unset. The CLI falls back to http://127.0.0.1:7331 | Send records to Studio |
WEFT_STUDIO_TOKEN | otel/env.go:42, cmd/weft/main.go:916, cmd/weft/token.go:61, cmd/weft/resolve.go:70 | The bearer token for the WEFT_STUDIO_URL destination and for the CLI’s API calls. On weft studio and weft dev it fixes the served token in place of <db>.token | Unset: no token sent; weft studio uses the database’s token file | Secure Studio |
WEFT_DB | otel/config.go:160, studio/studio.go:482, cmd/weft/main.go:929, cmd/weft/vacuum.go:134 | The SQLite file the local sink writes when otel.Local("") or the zero-config Install names no path; the database studio.New opens without a DB option; the database weft studio, weft dev and weft vacuum use when --db is not given. A bare file path, never a --db URL: a sqlite:// or clickhouse:// value is opened as a SQLite file of that name (weft CLI reference), so ClickHouse takes --db | ./.weft/weft.db | Record every run |
WEFT_DISCOVERY | internal/discovery/discovery.go:354, cmd/weft/resolve.go:46 | off (any case, spaces trimmed) stops apps and weft mcp from reading the discovery file a running weft studio or weft dev wrote, and since 0.18.0 stops weft studio and weft dev from writing it | Unset: apps read the file when WEFT_STUDIO_URL is unset; weft mcp reads it even then, for the token of a Studio at the same URL | Develop with weft dev |
XDG_RUNTIME_DIR | internal/discovery/discovery.go:106 | When set to an absolute path, $XDG_RUNTIME_DIR/weft is the discovery file’s second location, after ./.weft and before the user cache directory. weft studio writes the file to the first location of that order | Unset: ./.weft, then the user cache directory | Develop with weft dev |
WEFT_ENV | runtime/options.go:270, otel/pipeline.go:234, otel/pipeline.go:241, runtime/registry.go:182, internal/doctor/doctor.go:333 | dev lets runtime.Install open the playground link (else runtime.Enabled(true) must), and keeps the development-only otel.RawBodies(true), otel.DevDetail() and otel.Blocking() (else each is dropped with one WARN). In code, otel.DevMode() opens the same gate while WEFT_ENV is unset or under otel.NoEnv(); a WEFT_ENV set to anything but dev wins over it, with one WARN, otel: DevMode ignored: WEFT_ENV=<value>. The value is reported in the runtime’s registration, and weft doctor reports this shell’s value | Unset: no link; no raw bodies, layer spans or blocking queues unless the code sets otel.DevMode() | Connect your app to the playground |
OTEL_EXPORTER_OTLP_ENDPOINT | otel/env.go:47 | Adds an OTLP/HTTP destination with content off. An http:// value is the opt-in for plaintext to that host; no scheme means https:// | Unset: no such destination | Send records to any OTLP backend |
OTEL_EXPORTER_OTLP_HEADERS | otel/env.go:51 | Request headers for the OTEL_EXPORTER_OTLP_ENDPOINT destination only: comma-separated key=value pairs, percent-decoded (Authorization=Basic%20…) | Unset: no extra headers | Send records to any OTLP backend |
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT | otel/env.go:54 | true (any case) turns content on for the OTEL_EXPORTER_OTLP_ENDPOINT destination | Content off | Control what content leaves the process |
OTEL_SERVICE_NAME | runtime/registry.go:245, otel/pipeline.go:808 | The runtime’s service name, part of its stable runtime id; the pipeline’s service.name resource attribute, read by the OTel SDK. otel.Service overrides it for the pipeline | The binary’s name | Use your own OpenTelemetry SDK |
OTEL_RESOURCE_ATTRIBUTES | otel/pipeline.go:808 | Extra resource attributes, read by the OTel SDK’s resource detector; otel.Resource merges over them | Unset | Use your own OpenTelemetry SDK |
OTEL_EXPORTER_OTLP_TIMEOUT, OTEL_EXPORTER_OTLP_COMPRESSION, OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_KEY, their _TRACES_ and _LOGS_ forms; OTEL_BSP_*, OTEL_BLRP_* | The OTel SDK’s OTLP/HTTP exporters and batch processors, for every OTLP-backed destination, Studio’s included (otel/pipeline.go:766-785) | The SDK’s exporter and batching settings. weft sets the endpoint, the headers and, when an option asks, the timeout itself, and sizes the queues itself, so the queue-size variables have no effect | The SDK’s defaults | Send records to any OTLP backend |
With none of WEFT_STUDIO_URL, OTEL_EXPORTER_OTLP_ENDPOINT or a trusted discovery file, and no destination option, otel.Install() writes the local sink only. When one of them is present, the zero-option Install exports there instead and writes no local sink, so otel.LocalDB is nil. If every environment destination fails to build, it falls back to the local sink with one WARN. Pass otel.Local("") explicitly to keep both: explicit and environment destinations combine.
The weft command
Section titled “The weft command”Read by weft studio, weft dev, weft vacuum and the API clients. The flag of the same name wins over each variable. Each variable takes its flag’s value form, except WEFT_DB (above), which is a SQLite path where --db is a URL.
| Variable | Read by | Effect | Default | Explained in |
|---|---|---|---|---|
WEFT_STUDIO_ADDR | cmd/weft/main.go:510 | The listen address of weft studio and weft dev. Like --addr, it pins the address: a busy one is exit 1 | 127.0.0.1:7331, unpinned: a busy port moves to the next free one in 7331–7340 | weft CLI reference |
WEFT_MANIFEST | cmd/weft/main.go:525 | The weft.json Studio serves, read once at start; a file that cannot be read or parsed is a start error | The nearest weft.json from the working directory upward | Describe your agents in weft.json |
WEFT_RETAIN | cmd/weft/vacuum.go:34 | The retention for weft studio, weft dev and weft vacuum, as a Go duration (720h); runs last seen longer ago are swept. Under 1h, negative or unparsable is a usage error, exit 2 | Off: nothing is swept | Keep and delete recorded runs |
WEFT_PRICING | cmd/weft/pricing.go:27, studio/pricing.go:352 | A pricing table file that replaces the shipped one whole. A malformed file is exit 1 naming the path and the field from the CLI, and a panic from studio.New | The shipped studio/pricing.json | See what a run cost |
WEFT_LOG_LEVEL | cmd/weft/logflags.go:38 | The Studio server log’s level on weft studio and weft dev: debug, info, warn (or warning) or error, in any case; another value is a usage error | info when a format is set; with neither variable, Go’s default logger | Operate Studio |
WEFT_LOG_FORMAT | cmd/weft/logflags.go:42 | The server log’s format on stderr: text or json | text when a level is set | Operate Studio |
WEFT_STUDIO_URL, WEFT_STUDIO_TOKEN and WEFT_DB above are read by the command too. weft dev sets four variables for the app it starts, overriding the shell’s: WEFT_STUDIO_URL, WEFT_STUDIO_TOKEN, WEFT_DB (when Studio serves a file), and WEFT_ENV=dev unless the shell already set WEFT_ENV to a non-empty value.
| Variable | Read by | Effect | Default | Explained in |
|---|---|---|---|---|
WEFT_MODEL_REQUESTS | core/env.go:19 | deny makes every first-party adapter that built its own client fail its call with weft.ErrModelRequestsDenied before any network I/O. Read on every call, so t.Setenv toggles it per test. A client injected with Client(c) and the wefttest models ignore it | Unset: requests allowed | Connect a model provider |
WEFT_RECORD | Your test suite; weft never reads it | The suggested name for a suite’s own re-record switch: set, the suite builds its model with wefttest.Record; unset, with wefttest.Replay. The convention is in the godoc of wefttest.Record | — | Record a real conversation once, replay it forever |
WEFT_CLICKHOUSE_DSN | obsdb/contract_test.go:338, obsdb/contract_test.go:1022, the obsdb/clickhouse tests | A clickhouse:// DSN for weft’s own ClickHouse tests: the obsdbtest.Run conformance table, the record-contract fixtures and the option tests run against that server, each in a database it creates and drops | Unset: those tests skip | Choose the observability database |
OPENAI_MODEL, ANTHROPIC_MODEL, GEMINI_MODEL | openai/live_test.go:23, anthropic/live_test.go:23, google/live_test.go:26, behind the live build tag | The model each adapter’s live conformance run (go test -tags live, make live) calls. The run itself needs OPENAI_API_KEY, ANTHROPIC_API_KEY, or GEMINI_API_KEY (else GOOGLE_API_KEY), and skips without it | gpt-4o-mini, claude-sonnet-5, gemini-2.5-flash | Prove a provider adapter with the conformance suite |
WEFT_THREADTEST_CRASH_TURN, WEFT_THREADTEST_CRASH_MATRIX, WEFT_THREADTEST_CRASH_STORAGE | thread/threadtest/crashturn.go:43, thread/threadtest/crashturn.go:142, thread/threadtest/crashmatrix.go:788 | Set by threadtest’s crash harness for the child process it kills; never set them yourself. Your backend’s helper test opens its storage at WEFT_THREADTEST_CRASH_STORAGE | — | Write your own thread.Storage |
Provider SDKs
Section titled “Provider SDKs”The adapters build their SDK client with the options you pass; what you leave out, the SDK reads from the environment. openai.Model and anthropic.Model build their client when the model is built; google.Model builds it on the first run.
| Variable | Read by | Effect | Default | Explained in |
|---|---|---|---|---|
OPENAI_API_KEY | openai-go’s default client options | The API key when openai.APIKey is not passed | Unset: no key is sent | Connect a model provider |
OPENAI_BASE_URL | openai/model.go:207, openai/thinking.go:59 | The endpoint when openai.BaseURL is not passed. DialectAuto also reads it to guess the thinking dialect, with an injected client too. Since 0.20.0 the endpoint’s host is recorded on each request record as wire.server_address: BaseURL, else this variable, else api.openai.com | The SDK’s default, api.openai.com | Connect a model provider |
OPENAI_ORG_ID, OPENAI_PROJECT_ID | openai-go’s default client options | The organization and project headers | Unset | Connect a model provider |
ANTHROPIC_API_KEY | anthropic-sdk-go’s default client options | The API key when anthropic.APIKey is not passed | Unset | Connect a model provider |
ANTHROPIC_AUTH_TOKEN | anthropic-sdk-go’s default client options | A bearer token, used only when ANTHROPIC_API_KEY is unset or empty | Unset | Connect a model provider |
ANTHROPIC_PROFILE, ANTHROPIC_FEDERATION_RULE_ID, ANTHROPIC_ORGANIZATION_ID, ANTHROPIC_IDENTITY_TOKEN_FILE or ANTHROPIC_IDENTITY_TOKEN | anthropic-sdk-go’s default client options | With no API key or auth token: a named credentials profile, or workload identity federation (the rule id, the organization id, and an identity token from ANTHROPIC_IDENTITY_TOKEN_FILE, preferred, or the literal ANTHROPIC_IDENTITY_TOKEN) | Unset | Connect a model provider |
ANTHROPIC_CUSTOM_HEADERS | anthropic-sdk-go’s default client options | Extra request headers, one Name: value per line. Read only when the SDK found no credential at all: with an API key, auth token, profile or federation credential in the environment it is never sent | Unset | Connect a model provider |
ANTHROPIC_BASE_URL | anthropic/model.go:225 | The endpoint when anthropic.BaseURL is not passed. Since 0.20.0 the endpoint’s host is recorded on each request record as wire.server_address: BaseURL, else this variable, else api.anthropic.com | The SDK’s production endpoint | Connect a model provider |
GOOGLE_API_KEY, GEMINI_API_KEY | genai’s client config | The Gemini API key when google.APIKey is not passed. When both are set, GOOGLE_API_KEY wins and the SDK logs a warning | Unset | Connect a model provider |
GOOGLE_GENAI_USE_VERTEXAI | genai’s client config | 1 or true selects the Vertex AI backend; GOOGLE_GENAI_USE_ENTERPRISE wins when both are set. Vertex AI then needs GOOGLE_CLOUD_PROJECT (GOOGLE_CLOUD_LOCATION or GOOGLE_CLOUD_REGION, else global) with application default credentials, or an API key alone | The Gemini API backend | Connect a model provider |
GOOGLE_GENAI_USE_ENTERPRISE | genai’s client config | Selects the Vertex AI backend, overriding GOOGLE_GENAI_USE_VERTEXAI | Unset | Connect a model provider |
GOOGLE_VERTEX_BASE_URL | genai’s client config | The Vertex AI endpoint when google.BaseURL is not passed | The SDK’s default | Connect a model provider |
GOOGLE_GEMINI_BASE_URL | genai’s client config | The Gemini API endpoint when google.BaseURL is not passed | The SDK’s default | Connect a model provider |
A client passed with an adapter’s Client(c) option replaces these: the adapter builds no client and reads none of its SDK’s variables. One exception: openai’s DialectAuto still reads OPENAI_BASE_URL to guess the thinking dialect. This table lists the main SDK variables; the SDKs’ own documentation lists the rest (openai-go, anthropic-sdk-go, google.golang.org/genai).
Browser builds and examples
Section titled “Browser builds and examples”These are build-time variables of the devtools panel’s npm package and its Vite example, not read by any Go code.
| Variable | Read by | Effect | Default | Explained in |
|---|---|---|---|---|
import.meta.env.DEV | Your bundler (Vite); recommended in @weftgo/devtools’s mount and helper docs | Pass it as enabled: import.meta.env.DEV: a production build then mounts nothing and loads no panel | mount’s enabled defaults to true | Install the devtools panel |
WEFT_BACKEND | examples/devtools-vite/vite.config.ts:7 | The dev server’s proxy target for /run and /studio; vite build ignores it | http://127.0.0.1:8080 | Install the devtools panel |
VITE_WEFT_STUDIO | examples/devtools-vite/src/main.ts:17 | The panel’s endpoint in that example | /studio/ | Install the devtools panel |