Model Debugging and Observability
Use this guide to diagnose model connectivity and compatibility issues, inspect latency and token usage, collect traces, and record model calls.
Verify model connectivity
This section provides two verification methods. First, send a direct request to confirm that the model API is reachable. Then run the Midscene verification command to check model compatibility.
Send a direct request to the model service
The following curl request checks whether the Base URL, API key, and model name work. It only verifies basic model API connectivity. It does not check whether the model meets Midscene's compatibility requirements.
Use the Midscene verification command
This command checks both model connectivity and Midscene compatibility.
Put your model configuration in a .env file, then run:
The command reads the .env file in the current working directory. Dotenv debug logging is enabled by default, and values from .env override existing shell environment variables.
If the curl request succeeds but the Midscene verification command fails, the model API is reachable. Continue by checking the model capabilities and Midscene configuration.
Common configuration errors
MIDSCENE_MODEL_FAMILY is not set to a multimodal model
If you see MIDSCENE_MODEL_FAMILY is not set to a multimodal model with UI localization, make sure the MIDSCENE_MODEL_FAMILY environment variable for the multimodal model is set correctly.
Starting with version 1.0, Midscene recommends using MIDSCENE_MODEL_FAMILY to specify the multimodal model type. Legacy MIDSCENE_USE_... settings remain compatible but are deprecated.
See Supported models and setup for the correct model family and a complete configuration example.
Base URL or model name is incorrect
Confirm that MIDSCENE_MODEL_BASE_URL points to the provider's API endpoint. It commonly ends with a version such as /v1. Do not append /chat/completion, because the underlying SDK adds the request path.
Also confirm that MIDSCENE_MODEL_NAME matches a model available from that endpoint.
Improve model performance
If the model connects successfully but localization, planning, or page understanding is unstable, try the following:
- Review the replay report to confirm the task timeline is correct and the flow did not enter the wrong page or branch.
- Prefer newer officially supported versions within the same model series.
- Compare models from different providers with representative tasks, focusing on success rate, latency, and cost.
- For complex tasks, configure a separate Planning or Insight model. See Model strategy for the responsibilities of each model.
Debugging capabilities
Debug logs
Set DEBUG when you need additional diagnostic output. Common selectors include:
DEBUG=midscene:ai:profile:statsprints model latency and Token usage.DEBUG=midscene:ai:callprints AI response details.DEBUG=midscene:*prints all Midscene Debug logs.
For the complete selector list, log location, and handling notes, see Runtime configuration: Debug logs.
Usage statistics are also available in generated report files.
Record model calls
Set MIDSCENE_RECORD_MODEL_CALL=true to write model requests, responses, and streaming chunks to a JSONL file:
Each process creates one file, with one JSON event per line. Local recording is available only in Node.js and Electron. Browsers and Workers do not write local files. Codex App Server records also include available protocol metadata.
Every event has a type of request, chunk, response, or error. It also includes an executionId that groups calls from the same report execution, including retries. Calls outside a report execution, such as connectivity checks, use a generated ID prefixed with unscoped-.
Files contain request bodies, including custom extraBody, response headers and bodies, streaming responses, and possibly base64-encoded screenshots. Request headers are not recorded.
These files may be sensitive and large. Enable recording only while troubleshooting, and protect or delete the files afterward. The record format is not stable across versions.
Observability platforms
LangSmith
LangSmith is a platform for debugging large language models. Midscene provides automatic integration support through a dependency and environment variables.
Install the dependency
Set environment variables
After starting Midscene, you should see a log similar to:
Notes:
- LangSmith and Langfuse can be enabled simultaneously.
- This integration supports Node.js only. Browser environments throw an error.
- If you use
createOpenAIClient, it overrides the environment-variable integration.
For finer-grained control, such as enabling LangSmith only for specific tasks, use createOpenAIClient to wrap the client manually.
Langfuse
Langfuse is an LLM observability platform. Midscene integrates Langfuse's observeOpenAI wrapper to trace OpenAI API calls automatically.
Because Langfuse tracing uses OpenTelemetry, initialize the OpenTelemetry SDK when the application starts.
Install the dependencies
Initialize OpenTelemetry
Add this code at the very top of the application entry file:
Set environment variables
After starting Midscene, you should see logs similar to:
See the Langfuse OpenAI integration documentation for more configuration options and best practices.
Notes:
- LangSmith and Langfuse can be enabled simultaneously.
- This integration supports Node.js only. Browser environments throw an error.
- If you use
createOpenAIClient, it overrides the environment-variable integration.
Security considerations
- Do not commit
.envfiles, traces, debug logs, or model-call records to source control. - Review logs and traces before sharing them because they can contain model inputs, outputs, or screenshots.

