NVIDIA/SkillEvaluator / src/skillevaluator/tier3/reference_skills/api-caller
api-caller
VerifiedCall any REST API dynamically. Make GET, POST, PUT, DELETE requests to any endpoint with custom headers and JSON body.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 4.3 KB |
| evals/evals.json | config | 7.2 KB |
| references/common_apis.md | markdown | 1.5 KB |
| scripts/call_api.py | script | 8.3 KB |
| scripts/parse_openapi.py | script | 5.8 KB |
| scripts/url_safety.py | script | 527 B |
scripts/parse_openapi.py
View on GitHub#!/usr/bin/env python3
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""
Parse an OpenAPI spec and return available operations with their parameters.
Helps the LLM understand what endpoints are available and how to call them.
"""
import json
import sys
import urllib.error
import urllib.request
from url_safety import validate_http_url
def fetch_spec(url: str) -> dict:
"""Fetch OpenAPI spec from URL."""
try:
req = urllib.request.Request(validate_http_url(url), headers={"User-Agent": "api-caller/1.0"})
# validate_http_url() rejects non-HTTP schemes before this request.
with urllib.request.urlopen(req, timeout=30) as response: # nosec B310
content = response.read().decode("utf-8")
return json.loads(content)
except Exception as e:
return {"error": f"Failed to fetch spec: {e!s}"}
def parse_parameters(params: list) -> list:
"""Parse parameter definitions."""
result = []
for p in params:
schema = p.get("schema")
if schema is None:
schema = {}
description = p.get("description")
param_info = {
"name": p.get("name"),
"in": p.get("in"), # path, query, header, cookie
"required": p.get("required", False),
}
if isinstance(schema, bool):
param_info["schema"] = schema
elif isinstance(schema, dict):
param_info["type"] = schema.get("type", "string")
else:
param_info["type"] = "string"
param_info["description"] = description[:100] if isinstance(description, str) else ""
result.append(param_info)
return result
def parse_request_body(body: dict) -> dict:
"""Parse request body schema."""
if not body:
return None
content = body.get("content", {})
json_content = content.get("application/json", {})
schema = json_content.get("schema", {})
# Extract properties if it's an object
properties = schema.get("properties", {})
required = schema.get("required", [])
if properties:
fields = []
for name, prop in properties.items():
fields.append(
{
"name": name,
"type": prop.get("type", "string"),
"required": name in required,
"description": prop.get("description", "")[:50],
}
)
return {"fields": fields}
return {"type": schema.get("type", "object")}
def parse_spec(spec: dict, filter_path: str | None = None) -> dict:
"""Parse OpenAPI spec and extract operations."""
info = spec.get("info", {})
base_url = ""
# Get base URL from servers
servers = spec.get("servers", [])
if servers:
base_url = servers[0].get("url", "")
paths = spec.get("paths", {})
operations = []
for path, methods in paths.items():
# Optional: filter by path substring
if filter_path and filter_path.lower() not in path.lower():
continue
for method, details in methods.items():
if method in ["get", "post", "put", "delete", "patch"]:
parameters = details.get("parameters", [])
path_parameters = methods.get("parameters", [])
if (
isinstance(path_parameters, list)
and path_parameters
and isinstance(parameters, list)
and all(
isinstance(parameter, dict)
and "$ref" not in parameter
and isinstance(parameter.get("name"), str)
and isinstance(parameter.get("in"), str)
for parameter in [*path_parameters, *parameters]
)
):
merged = {(parameter["name"], parameter["in"]): parameter for parameter in path_parameters}
merged.update({(parameter["name"], parameter["in"]): parameter for parameter in parameters})
parameters = list(merged.values())
op = {
"method": method.upper(),
"path": path,
"full_url": f"{base_url}{path}" if base_url else path,
"operation_id": details.get("operationId", ""),
"summary": details.get("summary", "")[:100],
"parameters": parse_parameters(parameters),
}
# Parse request body for POST/PUT/PATCH
if method in ["post", "put", "patch"]:
body = parse_request_body(details.get("requestBody"))
if body:
op["request_body"] = body
operations.append(op)
return {
"api_name": info.get("title", "Unknown API"),
"version": info.get("version", ""),
"base_url": base_url,
"total_operations": len(operations),
"operations": operations[:20], # Limit to first 20 to avoid context bloat
}
def main():
if len(sys.argv) < 2:
print(
json.dumps(
{
"error": "Usage: parse_openapi.py <spec_url> [filter_path]",
"example": "parse_openapi.py https://api.weather.gov/openapi.json points",
},
indent=2,
),
file=sys.stderr,
)
sys.exit(1)
spec_url = sys.argv[1]
filter_path = sys.argv[2] if len(sys.argv) > 2 else None
# Fetch the spec
spec = fetch_spec(spec_url)
if "error" in spec:
print(json.dumps(spec, indent=2), file=sys.stderr)
sys.exit(1)
# Parse and return operations
result = parse_spec(spec, filter_path)
print(json.dumps(result, indent=2))
if __name__ == "__main__":
main()
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |