Local OpenAI-compat backend (openai_local)
Convenience backend name for a local OpenAI-compatible server (same client as
vllm / lmstudio / openai_compat). Profile load/unload and model inventory
stay in the host app — MechaHarness only issues chat completions.
Unlike vllm / lmstudio, this profile does not ship a default
base_url. Set MECHA_BASE_URL explicitly for your server.
Cloud OpenAI (openai + Luna)
The openai backend is the same Chat Completions client with default
base_url https://api.openai.com/v1. Prefer the cheap Luna model for live
graph tests.
export OPENAI_API_KEY=sk-... # or MECHA_API_KEY
unset MECHA_API_KEY # remove a local placeholder when using OPENAI_API_KEY
export MECHA_INFERENCE_BACKEND=openai
export MECHA_MODEL=gpt-6-luna
unset MECHA_BASE_URL # uses api.openai.com
mechaharness run "Reply with ok." \
--backend openai \
--family pass_through \
--model gpt-6-luna
apply_backend_defaults fills api_key from OPENAI_API_KEY when
MECHA_API_KEY is unset. Luna tool loops on Chat Completions get
reasoning_effort=none automatically when tools are present. The injected OpenAIRequestPolicy selects provider capabilities. Default cloud OpenAI
and Luna requests map max_tokens to max_completion_tokens and omit internal
runner metadata such as node_id from the HTTP body. Explicit request.extra
values take precedence for supported provider fields.
Offline / default pytest uses cassette Memory clients only — operator
OPENAI_API_KEY / MECHA_BASE_URL are ignored in static mode. To use cloud, select live mode and either set
MECHA_LIVE_OPENAI=1 or MECHA_INFERENCE_BACKEND=openai. An explicit
MECHA_BASE_URL always takes precedence, including one loaded from the local
env script; unset it to reach cloud OpenAI. The OpenAI opt-in configures the
reason lane; judge stories still need their own judge endpoint.
# Live-eligible stories against cloud Luna (explicit opt-in)
MECHA_LIVE_OPENAI=1 MECHA_MODEL=gpt-6-luna \
pytest -q tests/stories -k nubble_run_cost
Backend
export MECHA_BASE_URL=http://127.0.0.1:8000/v1 # or your host's OpenAI-compat URL
export MECHA_API_KEY=local # placeholder is fine for local vLLM
export MECHA_MODEL=<served-model-id>
mechaharness run "Reply with ok." \
--backend openai_local \
--family pass_through \
--model "$MECHA_MODEL"
Use the served model id your server advertises on /v1/models, not a
Hugging Face repo id.
Live and offline pytest use the dual-mode user story suite (see
User stories). Offline CI always runs cassettes; live hits
real HTTP for cassette twins and static infer / judge /
judge_route walks (tests/stories/live_capability.py). Behavioral expects
stay hard; cassette-exact token counts are soft.
# Full model-using live suite (reason + judge)
MECHA_STORY_BACKEND=live \
MECHA_BASE_URL=http://127.0.0.1:8000/v1 \
MECHA_MODEL=qwen3-30b-thinking \
MECHA_JUDGE_BASE_URL=http://127.0.0.1:8009 \
MECHA_JUDGE_MODEL=laya \
MECHA_MAX_TOKENS=1024 \
pytest -q tests/stories
# Reason-lane filter only
MECHA_STORY_BACKEND=live MECHA_STORY_MODEL=openai_compat/qwen3-30b-thinking \
MECHA_BASE_URL=http://127.0.0.1:8000/v1 \
pytest -q tests/stories -k nubble_run_cost
# shorthand
MECHA_LIVE_OPENAI_COMPAT=1 MECHA_BASE_URL=http://127.0.0.1:8000/v1 \
pytest -q tests/stories -k nubble_run_cost
Cursor / Codex MCP (guided coding)
For Agentic Recipe guided_coding, put the same MECHA_* endpoint knobs on the
MCP server env in a local .cursor/mcp.json (gitignored) or
.codex/config.toml (gitignored; see
codex-mcp.config.toml.example) and set
MECHA_MCP_HOST=project_coding. That loads ProjectCodingConfig (workspace
tools + local-work burst). See
Durable graph generators and
guided coding.
Optional CLI/pytest convenience: copy .env.example to
.env/env.sh (gitignored). Do not commit tokens, LAN IPs, or absolute home
paths.
Host Config
Discover which profile is loaded, map grants/lane, and attach tools in a host
MechaHarnessConfig subclass. Use
InferenceEnvironment.assert_compatible(require_media=True),
require_lane="judge", or required grants to refuse mismatched work.
Prefer ProjectCodingConfig when the host is the project workspace itself.
Judge lane (MECHA_JUDGE_*)
Judge is not OpenAI chat. Connection env binds on APIConnectionConfig
(SimpleHttpConnectionConfig.from_env), not Settings:
export MECHA_JUDGE_BASE_URL=http://127.0.0.1:8009
export MECHA_JUDGE_PATH=/v1/systemone # default; override if needed
export MECHA_JUDGE_MODEL=laya
# Judge filter (System One twins) or omit MECHA_STORY_MODEL for all live-eligible
MECHA_STORY_BACKEND=live MECHA_STORY_MODEL=systemone/laya \
MECHA_JUDGE_BASE_URL=http://127.0.0.1:8009 \
pytest -q tests/stories -k 'refund_verdict or systemone_cassette'
Legacy MECHA_DECIDE_* env names still work as aliases. Host apps typically load
decide-fast / decide-api profiles (filenames), expose judge tools, and map
those profiles to lane judge. See Judge reference.
Reason-only profiles must fail judge tools with a clear load hint.
Inspect a request without calling the provider
OpenAICompatStrategy.prepare_request(request) returns the normalized body plus
omitted field names. prepared.diagnostics() hashes every transmitted body
field, including tool descriptions and list order, without including raw prompt
values. It does not measure provider cache hits or include endpoint/tenant
routing in its digest. Host proxies can bind a custom policy through
get_openai_request_policy(). The inspect_openai_request CLI-universe verb
uses the same policy for offline comparisons.