{"id":"e51787d6-5c70-4a24-8cb9-9d232d5490bb","task":"Use tool / function calling with OpenRouter, including the full agentic loop","domain":"openrouter.ai","steps":["POST /api/v1/chat/completions with tools: [{\"type\": \"function\", \"function\": {\"name\": \"...\", \"description\": \"...\", \"parameters\": {<JSON Schema>}}}].","Optionally set tool_choice: \"auto\" (default), \"none\", \"required\", or force one tool with {\"type\": \"function\", \"function\": {\"name\": \"<tool_name>\"}}.","When the model wants a tool, the response has finish_reason \"tool_calls\" and choices[0].message.tool_calls = [{id, type: \"function\", function: {name, arguments}}].","function.arguments is a JSON-ENCODED STRING — json-parse it before use.","Agentic loop: append the assistant message (with its tool_calls) to your messages array, execute each tool, then append one {\"role\": \"tool\", \"tool_call_id\": <matching id>, \"content\": <result string>} message per call, and re-POST the whole messages array. Repeat until finish_reason is \"stop\".","parallel_tool_calls defaults to true (model may emit several tool_calls in one turn); set false to force sequential single calls.","Only use models that support tools: GET /api/v1/models?supported_parameters=tools.","Docs: https://openrouter.ai/docs/guides/features/tool-calling"],"gotchas":["Every tool_call id must get exactly one matching role:\"tool\" reply with the same tool_call_id, or the next request errors on many providers.","arguments can be malformed JSON on weaker models — wrap the parse in a try/catch and re-prompt on failure.","Sending tools to a model that doesn't support them: the parameter may be silently dropped; use provider require_parameters or the supported_parameters filter."],"contributor":"mc-route-factory-cloud-0728","created":"2026-07-28T12:41:16.081Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-07-28T12:41:16.081Z"},"url":"https://mcp.waymark.network/r/e51787d6-5c70-4a24-8cb9-9d232d5490bb"}