Skip to content

Environment variables

View as Markdown

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.

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.

VariableRead byEffectDefaultExplained in
WEFT_STUDIO_URLotel/env.go:39, internal/discovery/discovery.go:354, cmd/weft/resolve.go:60, internal/doctor/doctor.go:400Adds 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 hintUnset. The CLI falls back to http://127.0.0.1:7331Send records to Studio
WEFT_STUDIO_TOKENotel/env.go:42, cmd/weft/main.go:916, cmd/weft/token.go:61, cmd/weft/resolve.go:70The 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>.tokenUnset: no token sent; weft studio uses the database’s token fileSecure Studio
WEFT_DBotel/config.go:160, studio/studio.go:482, cmd/weft/main.go:929, cmd/weft/vacuum.go:134The 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.dbRecord every run
WEFT_DISCOVERYinternal/discovery/discovery.go:354, cmd/weft/resolve.go:46off (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 itUnset: 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 URLDevelop with weft dev
XDG_RUNTIME_DIRinternal/discovery/discovery.go:106When 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 orderUnset: ./.weft, then the user cache directoryDevelop with weft dev
WEFT_ENVruntime/options.go:270, otel/pipeline.go:234, otel/pipeline.go:241, runtime/registry.go:182, internal/doctor/doctor.go:333dev 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 valueUnset: 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_ENDPOINTotel/env.go:47Adds 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 destinationSend records to any OTLP backend
OTEL_EXPORTER_OTLP_HEADERSotel/env.go:51Request headers for the OTEL_EXPORTER_OTLP_ENDPOINT destination only: comma-separated key=value pairs, percent-decoded (Authorization=Basic%20…)Unset: no extra headersSend records to any OTLP backend
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENTotel/env.go:54true (any case) turns content on for the OTEL_EXPORTER_OTLP_ENDPOINT destinationContent offControl what content leaves the process
OTEL_SERVICE_NAMEruntime/registry.go:245, otel/pipeline.go:808The 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 pipelineThe binary’s nameUse your own OpenTelemetry SDK
OTEL_RESOURCE_ATTRIBUTESotel/pipeline.go:808Extra resource attributes, read by the OTel SDK’s resource detector; otel.Resource merges over themUnsetUse 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 effectThe SDK’s defaultsSend 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.

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.

VariableRead byEffectDefaultExplained in
WEFT_STUDIO_ADDRcmd/weft/main.go:510The listen address of weft studio and weft dev. Like --addr, it pins the address: a busy one is exit 1127.0.0.1:7331, unpinned: a busy port moves to the next free one in 7331–7340weft CLI reference
WEFT_MANIFESTcmd/weft/main.go:525The weft.json Studio serves, read once at start; a file that cannot be read or parsed is a start errorThe nearest weft.json from the working directory upwardDescribe your agents in weft.json
WEFT_RETAINcmd/weft/vacuum.go:34The 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 2Off: nothing is sweptKeep and delete recorded runs
WEFT_PRICINGcmd/weft/pricing.go:27, studio/pricing.go:352A 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.NewThe shipped studio/pricing.jsonSee what a run cost
WEFT_LOG_LEVELcmd/weft/logflags.go:38The 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 errorinfo when a format is set; with neither variable, Go’s default loggerOperate Studio
WEFT_LOG_FORMATcmd/weft/logflags.go:42The server log’s format on stderr: text or jsontext when a level is setOperate 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.

VariableRead byEffectDefaultExplained in
WEFT_MODEL_REQUESTScore/env.go:19deny 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 itUnset: requests allowedConnect a model provider
WEFT_RECORDYour test suite; weft never reads itThe 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_DSNobsdb/contract_test.go:338, obsdb/contract_test.go:1022, the obsdb/clickhouse testsA 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 dropsUnset: those tests skipChoose the observability database
OPENAI_MODEL, ANTHROPIC_MODEL, GEMINI_MODELopenai/live_test.go:23, anthropic/live_test.go:23, google/live_test.go:26, behind the live build tagThe 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 itgpt-4o-mini, claude-sonnet-5, gemini-2.5-flashProve a provider adapter with the conformance suite
WEFT_THREADTEST_CRASH_TURN, WEFT_THREADTEST_CRASH_MATRIX, WEFT_THREADTEST_CRASH_STORAGEthread/threadtest/crashturn.go:43, thread/threadtest/crashturn.go:142, thread/threadtest/crashmatrix.go:788Set 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

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.

VariableRead byEffectDefaultExplained in
OPENAI_API_KEYopenai-go’s default client optionsThe API key when openai.APIKey is not passedUnset: no key is sentConnect a model provider
OPENAI_BASE_URLopenai/model.go:207, openai/thinking.go:59The 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.comThe SDK’s default, api.openai.comConnect a model provider
OPENAI_ORG_ID, OPENAI_PROJECT_IDopenai-go’s default client optionsThe organization and project headersUnsetConnect a model provider
ANTHROPIC_API_KEYanthropic-sdk-go’s default client optionsThe API key when anthropic.APIKey is not passedUnsetConnect a model provider
ANTHROPIC_AUTH_TOKENanthropic-sdk-go’s default client optionsA bearer token, used only when ANTHROPIC_API_KEY is unset or emptyUnsetConnect a model provider
ANTHROPIC_PROFILE, ANTHROPIC_FEDERATION_RULE_ID, ANTHROPIC_ORGANIZATION_ID, ANTHROPIC_IDENTITY_TOKEN_FILE or ANTHROPIC_IDENTITY_TOKENanthropic-sdk-go’s default client optionsWith 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)UnsetConnect a model provider
ANTHROPIC_CUSTOM_HEADERSanthropic-sdk-go’s default client optionsExtra 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 sentUnsetConnect a model provider
ANTHROPIC_BASE_URLanthropic/model.go:225The 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.comThe SDK’s production endpointConnect a model provider
GOOGLE_API_KEY, GEMINI_API_KEYgenai’s client configThe Gemini API key when google.APIKey is not passed. When both are set, GOOGLE_API_KEY wins and the SDK logs a warningUnsetConnect a model provider
GOOGLE_GENAI_USE_VERTEXAIgenai’s client config1 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 aloneThe Gemini API backendConnect a model provider
GOOGLE_GENAI_USE_ENTERPRISEgenai’s client configSelects the Vertex AI backend, overriding GOOGLE_GENAI_USE_VERTEXAIUnsetConnect a model provider
GOOGLE_VERTEX_BASE_URLgenai’s client configThe Vertex AI endpoint when google.BaseURL is not passedThe SDK’s defaultConnect a model provider
GOOGLE_GEMINI_BASE_URLgenai’s client configThe Gemini API endpoint when google.BaseURL is not passedThe SDK’s defaultConnect 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).

These are build-time variables of the devtools panel’s npm package and its Vite example, not read by any Go code.

VariableRead byEffectDefaultExplained in
import.meta.env.DEVYour bundler (Vite); recommended in @weftgo/devtools’s mount and helper docsPass it as enabled: import.meta.env.DEV: a production build then mounts nothing and loads no panelmount’s enabled defaults to trueInstall the devtools panel
WEFT_BACKENDexamples/devtools-vite/vite.config.ts:7The dev server’s proxy target for /run and /studio; vite build ignores ithttp://127.0.0.1:8080Install the devtools panel
VITE_WEFT_STUDIOexamples/devtools-vite/src/main.ts:17The panel’s endpoint in that example/studio/Install the devtools panel