AGENT SKILL

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

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

  1. Define tool schemas: Create a tools array with JSON Schema definitions for each function, specifying name, description, and parameter types
  2. Send a request with tools: Include the tools array in your chat completion request; set tool_choice: "auto" to let the model decide when to call functions
  3. Parse tool calls: Extract tool_calls from response.choices[0].message, deserialize each function.arguments JSON string
  4. Execute and return results: Run each function locally, then send a follow-up request with role: "tool" messages containing the results
  5. 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

SamuelChien
SamuelChien/mega-skills-collection

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.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

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.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

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.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

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.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

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.

★ 0
SamuelChien
SamuelChien/mega-skills-collection

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'.

★ 0