81trust / 100

Openapi To Curl

by OpenAPI to curl command in Documents & files

x402 APIPassing, checked 5 h ago

Build a runnable curl command for one operation in an OpenAPI 3.x or Swagger 2.x spec. Locate the operation by operationId (preferred) or by method + path, substitute path parameters using the spec's example values, include required query and header parameters with their example values, and attach a JSON body when the operation defines one. Returns the structured request (method, url, headers, body) alongside the assembled curl string with POSIX single-quote escaping.

POST https://agent402.tools/api/openapi-to-curl

Last 30 days

All checks passedSome failedAll failedNot checked
Uptime
100%
Response time
179 ms typical, 179 ms slowest 5%
Last check
5 h ago
Next check
any minute now

How to call it

# See the payment challenge (nothing is charged)
curl -i -X POST "https://agent402.tools/api/openapi-to-curl" \
  -H "content-type: application/json" \
  -d '{"operationId":"getUser","spec":{"openapi":"3.0.0","paths":{"/users/{id}":{"get":{"operationId":"getUser","parameters":[{"in":"path","name":"id","required":true,"schema":{"example":"u_42","type":"string"}},{"in":"query","name":"fields","required":true,"schema":{"example":"name,email","type":"string"}}],"responses":{"200":{"description":"ok"}}}}},"servers":[{"url":"https://api.example.com"}]}}'
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const client = new x402Client().register(
  "eip155:8453",
  new ExactEvmScheme(privateKeyToAccount(process.env.AGENT_KEY)),
);
const pay = wrapFetchWithPayment(fetch, client);

// Not sure it's safe to pay? Preflight it first for $0.005:
// GET https://toolvet.app/api/v1/check?url=https%3A%2F%2Fagent402.tools%2Fapi%2Fopenapi-to-curl
const res = await pay("https://agent402.tools/api/openapi-to-curl", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({"operationId":"getUser","spec":{"openapi":"3.0.0","paths":{"/users/{id}":{"get":{"operationId":"getUser","parameters":[{"in":"path","name":"id","required":true,"schema":{"example":"u_42","type":"string"}},{"in":"query","name":"fields","required":true,"schema":{"example":"name,email","type":"string"}}],"responses":{"200":{"description":"ok"}}}}},"servers":[{"url":"https://api.example.com"}]}}),
});
console.log(await res.json());

Example input

{
  "operationId": "getUser",
  "spec": {
    "openapi": "3.0.0",
    "paths": {
      "/users/{id}": {
        "get": {
          "operationId": "getUser",
          "parameters": [
            {
              "in": "path",
              "name": "id",
              "required": true,
              "schema": {
                "example": "u_42",
                "type": "string"
              }
            },
            {
              "in": "query",
              "name": "fields",
              "required": true,
              "schema": {
                "example": "name,email",
                "type": "string"
              }
            }
          ],
          "responses": {
            "200": {
              "description": "ok"
            }
          }
        }
      }
    },
    "servers": [
      {
        "url": "https://api.example.com"
      }
    ]
  }
}

Example output

{
  "body": null,
  "curl": "curl -X GET 'https://api.example.com/users/u_42?fields=name%2Cemail'",
  "headers": {},
  "method": "GET",
  "url": "https://api.example.com/users/u_42?fields=name%2Cemail"
}

Security scan

  • No findings. We scan names, descriptions and tool definitions for hidden instructions and other prompt-injection patterns.

Recent checks

WhenResultHTTPTimePrice
5 h agoPassed402179 ms$0.002