# OnHub Code Execution API

> OnHub Code Execution API is a paid API for AI agents from api.onhub.ai, paid per call via x402, $0.015/call, status unknown (last checked 2026-10-02).

Writes and runs Python code to compute or verify an answer, returning the generated code, its output, and a final human-readable result

## Facts

- Endpoint: POST https://api.onhub.ai/v1/code?utm_source=zero.xyz
- Price: $0.015/call
- Payment: x402
- Status: unknown
- Last checked: 2026-10-02
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/onhub-code-execution-api-2aeb3fe1
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_A3Laii9t5A2ADMQxd_SoV

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability onhub-code-execution-api-2aeb3fe1 -d '<json body>'
```

Example prompt: Can you calculate what the sum of the squares of the first 100 Fibonacci numbers is? Write and run the Python code to get me the exact answer.

## When to prefer this

Choose this endpoint when you need a precise, verifiable answer to a computational or mathematical question and want to see the Python code and its raw output alongside the result. It is especially valuable when correctness must be demonstrated (not just asserted), when calculations involve large numbers or complex sequences, or when you need to verify a claim programmatically. Prefer it over plain text inference endpoints for any task where running actual code produces a more trustworthy answer than language model estimation.

## Known failure modes

- Query too short (below 3 characters) or too long (above 2000 characters) returns a validation error
- Code execution errors such as division by zero or import of unavailable libraries may result in an error step rather than a valid answer
- Ambiguous or non-computational queries may produce incorrect or nonsensical Python code
- Network timeout if the code execution takes too long for complex computations
- Payment failure via x402 protocol if insufficient USDC balance

## How this service works

Writes and runs Python to compute or verify an answer, returning the code, its output, and a final answer.

## Output

Returns a JSON object containing the original query, an array of steps (each with a type and content field showing the code output), and a final human-readable answer string summarizing the computed result, along with an object type identifier 'code.result'.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "query": {
   "type": "string",
   "maxLength": 2000,
   "minLength": 3,
   "description": "A computational question to answer by writing and running Python code, e.g. a calculation, data-processing, or verification task."
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "query": "What is the sum of the first 50 prime numbers?",
  "steps": [
   {
    "type": "result",
    "content": "5117\n"
   }
  ],
  "answer": "The sum of the first 50 prime numbers is 5,117.",
  "object": "code.result"
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/onhub-code-execution-api-2aeb3fe1/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from api.onhub.ai](https://www.zero.xyz/host/api.onhub.ai/llms.txt)
