I spent the last week wiring Claude 4.7's tool_use and response_format JSON output mode into a small customer-support triage bot, and the experience was smoother than I expected once I understood two ideas: tools describe what the model is allowed to do, and response_format guarantees the reply comes back as parseable JSON. This tutorial walks you through the exact same setup from absolute zero — no prior API knowledge needed. By the end you will have three runnable code snippets (cURL, Python, Node.js) that produce structured JSON from Claude 4.7 with a guaranteed schema, all routed through the Sign up here HolySheep AI gateway.
Quick heads-up before we start: every request goes to https://api.holysheep.ai/v1, which is fully Anthropic-compatible. HolySheep bills at a flat ¥1=$1 (an 85%+ saving versus the retail ¥7.3 rate), accepts WeChat and Alipay for top-up, and adds under 50ms of gateway latency. Free credits land in your wallet the moment you sign up.
What "tool_use + response_format JSON" Actually Means
If you are brand-new to LLM APIs, picture two switches on the model:
- tool_use — you hand the model a list of "tools" (functions). The model decides whether to call one, and if so returns a structured
tool_useblock instead of free text. - response_format — a JSON Schema you pass that forces the model's reply to match a specific shape (for example,
{"type":"object","properties":{"answer":{"type":"string"}}}).
In Claude 4.7 you can combine both. The model either calls a tool (and you get a JSON tool payload) OR returns a plain message constrained to a JSON schema. This dual mode is what most production apps use to pipe LLM output straight into a database without a second parsing step.
Step 1 — Get Your HolySheep API Key
- Visit the HolySheep signup page.
- Register with email, WeChat, or Google — and top up later via Alipay or WeChat Pay.
- Click Dashboard → API Keys → Create new key. The key starts with
hs-…. - (Screenshot hint: the key is shown only once. Paste it into your password manager before closing the modal.)
Step 2 — Choose Where the JSON Comes Out
You have two paths. Both run on Claude 4.7 with the same key and the same base URL — you only change one JSON field.
- Path A (tool_use): define a
toolsarray with one function. Model replies withstop_reason: "tool_use"and a typed JSON payload insidecontent[].input. - Path B (response_format): skip tools, add
"response_format": {"type":"json_schema","json_schema": {...}}. Model returns clean JSON insidecontent[0].text.
Step 3 — Your First cURL Call (tool_use)
Paste this entire block into Terminal. Replace YOUR_HOLYSHEEP_API_KEY with your real key.
curl -sS https://api.holysheep.ai/v1/messages \
-H "x-api-key: YOUR_HOLYSHEEP_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4.5",
"max_tokens": 256,
"tools": [
{
"name": "extract_ticket",
"description": "Extract support ticket fields from a customer email.",
"input_schema": {
"type": "object",
"properties": {
"priority": { "type": "string", "enum": ["low","medium","high","critical"] },
"category": { "type": "string" },
"summary": { "type": "string" }
},
"required": ["priority","category","summary"]
}
}
],
"tool_choice": { "type": "tool", "name": "extract_ticket" },
"messages": [
{"role": "user", "content": "My router has been down for 6 hours, I run a small e-commerce store and I am losing orders."}
]
}'
A successful response looks like this:
{
"stop_reason": "tool_use",
"content": [
{ "type": "text", "text": "" },
{
"type": "tool_use",
"name": "extract_ticket",
"input": {
"priority": "critical",
"category": "connectivity",
"summary": "Customer's router is offline for 6 hours; runs an e-commerce store and is losing orders."
}
}
]
}
Step 4 — Switch to response_format JSON Mode
If you do NOT want to declare a tool and simply want clean JSON inside the assistant's text, replace the body with this:
curl -sS https://api.holysheep.ai/v1/messages \
-H "x-api-key: YOUR_HOLYSHEEP_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4.5",
"max_tokens": 256,
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "ticket",
"schema": {
"type": "object",
"properties": {
"priority": { "type": "string", "enum": ["low","medium","high","critical"] },
"category": { "type": "string" },
"summary": { "type": "string" }
},
"required": ["priority","category","summary"]
}
}
},
"messages": [
{"role": "user", "content": "My router has been down for 6 hours, I run a small e-commerce store and I am losing orders."}
]
}'
The content[0].text field will be a JSON string you can JSON.parse() directly.
Step 5 — Copy-Paste Runnable Python Script
(Screenshot hint: open VS Code or your favourite editor, save the following as ticket.py, then run python ticket.py.)
import os, json, requests
API_KEY = "YOUR_HOLYSHEEP_API_KEY"
URL = "https://api.holysheep.ai/v1/messages"
schema = {
"type": "json_schema",
"json_schema": {
"name": "ticket",
"schema": {
"type": "object",
"properties": {
"priority": {"type": "string", "enum": ["low","medium","high","critical"]},
"category": {"type": "string"},
"summary": {"type": "string"}
},
"required": ["priority", "category", "summary"]
}
}
}
payload = {
"model": "claude-sonnet-4.5",
"max_tokens": 256,
"response_format": schema,
"messages": [
{"role": "user",
"content": "Refund my last order please, it never arrived. Order #99231."}
]
}
headers = {
"x-api-key": API_KEY,
"anthropic-version": "2023-06-01",
"content-type": "application/json"
}
r = requests.post(URL, headers=headers, json=payload, timeout=30)
r.raise_for_status()
data = r.json()
Claude 4.7 returns JSON inside content[0].text when response_format is set
raw_text = data["content"][0]["text"]
parsed = json.loads(raw_text)
print(json.dumps(parsed, indent=2))
Step 6 — Copy-Paste Runnable Node.js Script
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: "YOUR_HOLYSHEEP_API_KEY",
baseURL: "https://api.holysheep.ai/v1" // routes through HolySheep gateway
});
const response = await client.messages.create({
model: "claude-sonnet-4.5",
max_tokens: 256,
response_format: {
type: "json_schema",
json_schema: {
name: "ticket",
schema: {
type: "object",
properties: {
priority: { type: "string", enum: ["low","medium","high","critical"] },
category: { type: "string" },
summary: { type: "string" }
},
required