Example: Integrating Cursor with TensorZero
Caution
This example is deprecated and unmaintained. Use at your own risk.
Note
Read more about this integration on our blog: Reverse Engineering Cursor's LLM Client
This example shows how to use the TensorZero Gateway as a proxy between Cursor and the LLM APIs — enabling you to observe LLM calls being made, run evaluations on individual inferences, use inference-time optimizations, and even experiment with and optimize the prompts and models that Cursor uses.
Setup
- Create a
.envfile with the credentials for the LLM providers you want to use (as in any other TensorZero deployment). Our example uses OpenAI, Anthropic, and Google AI Studio, but you can use any LLM provider TensorZero supports. See.env.examplefor an example. - Generate a strong API key to protect your gateway endpoint from unauthorized access.
Set it as the value for
API_TOKENin your.envfile. We've had some issues with special characters in this step so recommend you use an alphanumeric string to be safe. Optionally, setUSER="yourname"if you'd like to tag each request with your name for downstream use. - Create an ngrok account.
Grab your auth token and add it to the
.envfile as the value forNGROK_AUTHTOKEN. - Run
docker compose upto stand up ClickHouse, the TensorZero Gateway, the TensorZero UI, Nginx, and ngrok. To avoid port conflicts, ClickHouse and TensorZero services that would normally bind to portsXXXXbind to1XXXXinstead (e.g.3000→13000).- If you're using Windows (non-WSL), you might need to fix line endings with the PowerShell command:
(Get-Content ./nginx/entrypoint.sh -Raw) -replace "`r`n", "`n" | Set-Content ./nginx/entrypoint.sh -NoNewline -Encoding UTF8
- If you're using Windows (non-WSL), you might need to fix line endings with the PowerShell command:
- Visit
http://localhost:4040and grab your ngrok URL. - Set your Cursor
OPENAI_BASE_URLto your ngrok URL with the/openai/v1suffix (e.g.https://your-id.ngrok-free.app/openai/v1). This should be available in your Cursor model settings. - Set your OpenAI API key to the
API_TOKENvalue you set in your.envfile (not your OpenAI API key!). - Turn off all the models in Cursor and add a custom one called
tensorzero::function_name::cursorzero. - Verify the new OpenAI connection by turning on your custom API key.
Now, you can use Cursor as you normally would but with the tensorzero::function_name::cursorzero model you defined.
This will send all traffic through your self-hosted TensorZero Gateway, which in turn will route those requests to the LLM APIs you defined in your tensorzero.toml file.
Take a look at the server running on http://localhost:14000 to see what your requests look like!
Intercepting Cursor Tab Requests
This section is mostly for reference. You do not need to do this to run the Cursor integration today.
- Install
mitmproxy, and install the root certificate system-wide. - Turn off HTTP2 in VS Code settings. [reference]
- Start Cursor with the environment variables
http_proxy=http://localhost:8080andhttps_proxy=http://localhost:8080.
A Haiku about This Integration
Cursor calls go through
TensorZero watches them
See the requests flow