openrouter-function-calling
Implement function/tool calling with OpenRouter models. Use when building agents or structured outputs. Trigger with phrases like 'openrouter functions', 'openrouter tools', 'openrouter agent', 'function calling'.
- License 许可
- MIT
- 最近更新
- 2026-05-26
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- openrouter-function-calling
- author
- Jeremy Longshore <jeremy@intentsolutions.io>
- license
- MIT
- version
- 1.0.0
- description
- Implement function/tool calling with OpenRouter models. Use when building agents or structured outputs. Trigger with phrases like 'openrouter functions', 'openrouter tools', 'openrouter agent', 'function calling'.
- allowed-tools
- Read, Write, Edit, Grep
- compatible-with
- claude-code, codex, openclaw
02 资源文件 9
- 参考文档references/advanced-tool-definitions.md3.0 KB
- 参考文档references/basic-function-calling.md3.0 KB
- 参考文档references/errors.md323 B
- 参考文档references/examples.md4.2 KB
- 参考文档references/forced-tool-use.md821 B
- 参考文档references/model-compatibility.md979 B
- 参考文档references/parallel-tool-calls.md1.1 KB
- 参考文档references/streaming-with-tools.md2.0 KB
- 参考文档references/tool-router.md1.4 KB
03 SKILL.md 正文
Openrouter Function Calling
Overview
This skill demonstrates implementing function calling and tool use patterns with OpenRouter-supported models.
Prerequisites
- OpenRouter integration
- Model that supports function calling (GPT-4, Claude, etc.)
Instructions
- Define tool schemas: Create a
toolsarray with JSON Schema definitions for each function, specifying name, description, and parameter types - Send a request with tools: Include the
toolsarray in your chat completion request; settool_choice: "auto"to let the model decide when to call functions - Parse tool calls: Extract
tool_callsfromresponse.choices[0].message, deserialize eachfunction.argumentsJSON string - Execute and return results: Run each function locally, then send a follow-up request with
role: "tool"messages containing the results - Handle multi-turn loops: Continue the request-execute-respond cycle until the model returns a final text response without tool calls
Output
- Model-generated function calls with properly typed arguments
- Multi-turn conversation with tool execution results fed back to the model
- Final synthesized response incorporating tool outputs
Error Handling
| Error | Cause | Fix |
|---|---|---|
tool_calls is null |
Model chose not to call tools or doesn't support them | Check model compatibility; use tool_choice: "required" to force |
| JSON parse error on arguments | Model generated malformed JSON | Wrap JSON.parse in try/catch; retry with a more capable model |
| 400 invalid tool schema | Schema has unsupported types or format | Use only JSON Schema draft-07 types; avoid $ref or complex constructs |
See ${CLAUDE_SKILL_DIR}/references/errors.md for full error reference.
Examples
See ${CLAUDE_SKILL_DIR}/references/examples.md for runnable code samples.
Resources
04 同仓库更多 Skills
zustand-store-ts
Create Zustand stores with TypeScript, subscribeWithSelector middleware, and proper state/action separation. Use when building React state management, creating global stores, or implementing reactive state patterns with Zustand.
zustand-store-creator
Zustand Store Creator - Auto-activating skill for Frontend Development. Triggers on: zustand store creator, zustand store creator Part of the Frontend Development skill category.
zero-trust-config-helper
Zero Trust Config Helper - Auto-activating skill for Security Advanced. Triggers on: zero trust config helper, zero trust config helper Part of the Security Advanced skill category.
zapier-integration-helper
Zapier Integration Helper - Auto-activating skill for Business Automation. Triggers on: zapier integration helper, zapier integration helper Part of the Business Automation skill category.
zai-cli
Execute z.AI CLI providing vision, search, reader, and GitHub exploration via CLI and MCP. Use when user needs image/video analysis, OCR, UI-to-code conversion, error diagnosis, real-time web search, web page to markdown extraction, or GitHub code exploration. Trigger with phrases like "analyze this image", "search the web for", "read this page", "explore this repo", or "use zai". Requires Z_AI_API_KEY.
yt-research
Research competitor YouTube channels, niches, and trending topics for your content strategy. Use this skill whenever the user says "research channels", "analyze competitors", "find trending topics", "niche analysis", "competitive research", "what are other creators doing", "scrape YouTube channels", or wants to understand the competitive landscape for a specific tool or topic area. Use when working with yt research. Trigger with 'yt', 'research'.