Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

Back to skills

Claude Code Api Request

ASecurity

Use when implementing server-side HTTP request handling for a Claude Code compatible Anthropic API gateway, especially /v1/messages, /v1/messages/count_tokens, /v1/files, /v1/models, headers, body fields, beta handling, and gateway routing.

4 stars
0 votes
0 copies
0 views
Added 9/20/2026
businessapi

Works with

claude codecliapi

Security Analysis

A100/100

Scanned 9/20/2026

Install to Claude Code

$npx -y skills add ZipperCode/lingma2api --skill claude-code-api-request --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Claude Code Api Request?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Claude Code Api Request
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/zippercode-claude-code-api-request/badge)](https://www.skillsdirectory.com/skills/zippercode-claude-code-api-request)

More formats (shields.io, HTML) on the badges page.

Download Zip
Files
SKILL.md
---
name: claude-code-api-request
description: Use when implementing server-side HTTP request handling for a Claude Code compatible Anthropic API gateway, especially /v1/messages, /v1/messages/count_tokens, /v1/files, /v1/models, headers, body fields, beta handling, and gateway routing.
---

# Claude Code 网关 HTTP 请求合同

## 目标

根据本 skill,实现大模型请求网关的 HTTP 接口层。你是在写服务端 endpoint,不是在写 Claude Code 客户端 SDK 调用。

主入口请先读 `claude-code-llm-gateway`。本 skill 只负责 HTTP contract:路径、headers、query、body、响应和错误。

## 必须实现的入口

| Endpoint | Method | 用途 |
|---|---|---|
| `/v1/messages` | POST | 主模型请求,支持流式和非流式 |
| `/v1/messages?beta=true` | POST | 同上;`beta=true` 只作兼容开关 |
| `/v1/messages/count_tokens` | POST | token 统计 |
| `/v1/files` | POST | multipart 文件上传 |
| `/v1/files` | GET | 文件列表 |
| `/v1/files/{file_id}/content` | GET | 文件下载 |
| `/v1/models` | GET | 模型列表/能力缓存 |

详细字段表见 `references/request-wire-format.md`。

## 公共处理流程

1. 解析鉴权:接受 `Authorization: Bearer <token>` 和 `x-api-key`。网关可自行决定映射关系,但不能因为 Claude Code 使用其中一种就拒绝另一种。
2. 解析公共头:`anthropic-version`、`anthropic-beta`、`x-app`、`User-Agent`、`X-Claude-Code-Session-Id`、`x-client-request-id`。
3. 读取 body 并做宽松校验:必需字段缺失才 400;未知字段默认忽略或透传。
4. 将 `model` 映射到你的上游模型。
5. 根据 `stream` 分支:
   - `true`:交给 SSE 子协议,见 `claude-code-api-streaming`。
   - `false` 或缺失:返回完整 Anthropic message JSON。
6. 按 Anthropic 风格返回错误 JSON,并保留可重试状态码语义。

## /v1/messages 最小 body 支持

必须识别:

```json
{
  "model": "claude-sonnet-4-5",
  "messages": [],
  "system": [],
  "tools": [],
  "tool_choice": { "type": "auto" },
  "max_tokens": 8000,
  "thinking": { "type": "adaptive" },
  "temperature": 1,
  "metadata": { "user_id": "..." },
  "stream": true,
  "betas": [],
  "context_management": { "edits": [] },
  "output_config": {},
  "speed": "fast"
}
```

兼容要求:

- `thinking.budget_tokens` 必须小于 `max_tokens`;不支持 thinking 时忽略或降级。
- `tools` 可能包含普通工具、deferred tool、server tool。不要因为未知工具字段直接失败。
- `messages` 中可能含 `tool_result`、`thinking`、`redacted_thinking`、`cache_edits`、`cache_reference`。
- `betas` 和 `anthropic-beta` 都可能出现;建议合并后作为能力开关。

## /v1/messages/count_tokens

返回:

```json
{ "input_tokens": 1234 }
```

如果没有精确 tokenizer,可以稳定估算。字段类型必须是 number。

## Files API

上传:`POST /v1/files`,multipart 字段 `file` 和 `purpose=user_data`。返回至少 `id`、`filename`、`size_bytes`。

列表:`GET /v1/files?after_created_at=...&after_id=...`。返回 `{ data: [], has_more: false }`。

下载:`GET /v1/files/{file_id}/content`。返回二进制 body。

## Models API

`GET /v1/models` 返回 `{ data: [...], has_more: false }`。如果你的平台只有静态模型,返回静态列表即可。

## 错误与重试

- 400:字段真正非法才返回。
- 401/403:认证或权限失败。
- 408/409/429/5xx/529:Claude Code 会按可重试错误处理;429 可带 `retry-after`。
- 404:如果只是不支持 stream endpoint,Claude Code 可能尝试非流式 fallback;但 `/v1/messages` 本身最好不要 404。

Attribution

ZipperCodeZipperCode
View sourceMore from ZipperCode →
SSkills DirectorySkills Directory

Your tool, in front of Claude Code builders.

3 founder slots · $299/mo · GSC-verified traffic · sponsors can never buy grades.

See placements

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Your tool, in front of Claude Code builders.

3 founder slots · $299/mo · GSC-verified traffic · sponsors can never buy grades.

See placements

Related Skills

Solution Architect

Designs system architecture, component specifications, and technical integration strategy. Use when: designing solutions, system architecture, technology stack, or integration approaches.

192 votes

Akorchak:Venture Assessment

Generate a comprehensive VC investment assessment report for a company

72 votes

Stock Analysis

Analyze stocks and cryptocurrencies using Yahoo Finance data. Supports portfolio management (create, add, remove assets), crypto analysis (Top 20 by market cap), and periodic performance reports (daily/weekly/monthly/quarterly/yearly). 8 analysis dimensions for stocks, 3 for crypto. Use for stock analysis, portfolio tracking, earnings reactions, or crypto monitoring.

6511 votes

Just Fucking Cancel

Find and cancel unwanted subscriptions by analyzing bank transactions. Detects recurring charges, calculates annual waste, and helps you cancel with direct URLs and browser automation. Use when: 'cancel subscriptions', 'audit subscriptions', 'find recurring charges', 'what am I paying for', 'save money', 'subscription cleanup', 'stop wasting money'. Supports CSV import (Apple Card, Chase, Amex, Citi, Bank of America, Capital One, Mint, Copilot) OR Plaid API for automatic transaction pull. Out...

6511 votes

Telegram Compose

Compose rich, readable Telegram messages using HTML formatting via direct Telegram API. Use when: (1) Sending any Telegram message beyond a simple one-line reply, (2) Creating structured messages with sections, lists, or status updates, (3) Need formatting unavailable via Clawdbot's Markdown conversion (underline, spoilers, expandable blockquotes, user mentions by ID), (4) Sending alerts, reports, summaries, or notifications to Telegram, (5) Want professional, scannable message formatting wit...

6511 votes
View all in business →