Docs

Vercel AI SDK tools

Two tools for the Vercel AI SDK, from the onlinecompiler npm package: runCode lets a model run a program in 46 languages and read its output, and runTests lets it judge code against test cases. Every run is in a fresh sandbox with no network.

Terminal
npm install onlinecompiler ai

The tools need ai version 5 or later. Set ONLINECOMPILER_API_KEY to an API key from the dashboard (free, no card), then hand the tools to the model:

example.js
import { generateText, stepCountIs } from 'ai';
import { onlinecompilerTools } from 'onlinecompiler/ai-sdk';

const { text } = await generateText({
  model: 'openai/gpt-5-mini',
  tools: onlinecompilerTools(), // reads ONLINECOMPILER_API_KEY
  stopWhen: stepCountIs(5),
  prompt: 'What is the 40th Fibonacci number? Compute it, don\'t guess.',
});
console.log(text);

The tools

  • runCode takes compiler, code and optional input, and runs the program as /api/run-code-sync/ does: up to 30 seconds and 512 MB, no network. Exit code 124 means it ran out of time.
  • runTests takes compiler, code and tests (each an input and an expected_output), with an optional checker (trim, exact, tokens, float, rows), tolerance and time limit, and judges as /api/run-tests/ does: an overall verdict, a score and a verdict per test.
  • onlinecompilerTools() gives both, sharing one client. Each function takes the client's options (apiKey, baseUrl, timeout, fetch) or a client you made.
tools.js
import { runTests } from 'onlinecompiler/ai-sdk';

const tools = {
  // Only the judging tool, with the key passed in instead of read from the environment.
  runTests: runTests({ apiKey: process.env.MY_ONLINECOMPILER_KEY }),
};

What the model gets back

runCode returns the run's result, with any files the program wrote listed by name and link, not their contents:

runCode result
{
  "status": "success",
  "exit_code": 0,
  "output": "102334155\n",
  "error": "",
  "time": "0.0213",
  "memory": "9216",
  "truncated": false,
  "files": []
}

runTests returns verdict, score, passed, total, compile_error, a plain-words summary, each test's verdict, output and time, and the submission id, under which the full result and its signed receipt stay available. An error from the API (a bad key, a limit reached) reaches the model as a failed tool call.

The same client covers the rest of the API: see the Node.js client. Agents in Claude, ChatGPT, Cursor and VS Code can use the MCP server instead.

Questions

Which AI SDK versions does it work with?
Version 5 and later. The tools are plain AI SDK tools, so generateText, streamText and agents all take them.
Does the model see file contents or the signed receipt?
No. To keep the model's context small, runCode returns files by name, type, size and link, and runTests leaves out the receipt. Call the client directly when you need them.
How many runs does it use?
Each runCode call is one run, and each test in a runTests call is one run, from your API key's allowance. The Free plan has 100,000 runs a month.
Can I use it in the browser?
Keep it on your server: an API key in a browser bundle can be copied. For an AI app in Claude, ChatGPT, Cursor or VS Code, the MCP server needs no code at all.