Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx skills add wangjianqi/AppStore --skill 04-llm-api-integrationgit clone --depth 1 https://github.com/wangjianqi/AppStoreWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/wangjianqi/appstore/04-llm-api-integration)<a href="https://agentmods.dev/skills/wangjianqi/appstore/04-llm-api-integration"><img src="https://agentmods.dev/badge/skills/wangjianqi/appstore/04-llm-api-integration.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00054 | $0.00860 |
| Opus 5 | $0.00027 | $0.00430 |
| Sonnet 5 | $0.00011 | $0.00172 |
| Haiku 4.5 | $0.00005 | $0.00086 |
Grade A, and why
llm-api-integration scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
What it actually says
LLM API 集成
网络层架构
服务协议
protocol LLMServiceProtocol {
func chat(messages: [ChatMessage]) async throws -> ChatResponse
func chatStream(messages: [ChatMessage]) -> AsyncThrowingStream<StreamChunk, Error>
func cancelCurrentRequest()
}
请求模型
- 使用 OpenAI 兼容格式(大多数国内外 API 支持)
- 请求体包含 model、messages、temperature、max_tokens、stream
- messages 数组中每条消息有 role(system/user/assistant)和 content
响应模型
- 非流式:完整响应包含 choices 数组,每个 choice 有 message 和 usage
- 流式:SSE 格式,每个 data 行是一个 delta 片段
- usage 包含 prompt_tokens 和 completion_tokens
流式输出(SSE)
实现要点
- 使用 URLSession.bytes(byLine:) 逐行读取 SSE 数据
- 解析 "data: " 前缀的行
- 处理 "data: [DONE]" 终止信号
- 在 ViewModel 中使用 @Published 属性更新 UI
- 支持取消流式请求(Task 取消)
错误处理
- 网络超时:设置合理的 URLSessionConfiguration.timeoutInterval
- API 限流:实现指数退避重试
- Token 超限:截断上下文或提示用户
- JSON 解析失败:跳过无效行继续处理
API Key 安全
安全策略
- ⚠️ 绝不在客户端代码中硬编码 API Key
- 推荐方案:通过自有后端代理转发 API 请求
- 备选方案:Keychain 存储 + 环境配置(Debug/Release 不同 Key)
- 最差方案:Info.plist 存储(仍可被提取,仅用于开发阶段)
后端代理架构
iOS App → 自有后端(验证用户身份)→ LLM API
Token 管理
用量追踪
- 每次请求记录 prompt_tokens 和 completion_tokens
- 本地累计存储(UserDefaults 或 SwiftData)
- 提供用量统计 UI
成本控制
- 设置单次请求 max_tokens 上限
- 设置用户每日/每月配额
- 上下文截断策略:保留最近 N 条消息或 Token 预算内消息
- 优先使用较便宜的模型处理简单请求
国产大模型 API 适配
OpenAI 兼容格式
大多数国产大模型支持 OpenAI 兼容格式,只需修改 baseURL:
| 模型 | baseURL |
|---|---|
| 通义千问 | https://dashscope.aliyuncs.com/compatible-mode/v1 |
| DeepSeek | https://api.deepseek.com/v1 |
| 智谱 GLM | https://open.bigmodel.cn/api/paas/v4 |
差异注意
- 部分 API 的错误码格式不同
- 部分模型不支持 function calling
- 流式输出的 SSE 格式可能有细微差异
SwiftUI 集成
ViewModel 模式
- 使用 @Observable 或 ObservableObject
- messages 数组驱动 UI 刷新
- 流式输出时逐字更新最后一条 assistant 消息
- isLoading 状态控制发送按钮和打字指示器
UI 组件
- LazyVStack + ScrollViewReader 实现消息列表
- 自动滚动到底部
- 打字指示器动画
- Markdown 渲染(MarkdownUI 库或 AttributedString)
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 8d ago First seen · 109 lines · 54 tokens per session scan A 2603bf0dfe35
llm-api-integration is a skill published in the GitHub repository wangjianqi/AppStore (11 stars, last pushed 3mo ago), licensed MIT. It adds 54 tokens to every session and 860 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other skills, from other repositories
maui-essentials-ai
Adopt Microsoft.Maui.Essentials.AI for local/on-device MAUI AI. USE FOR: Apple Intelligence chat, IChatClient, iOS/macOS/Mac Catalyst 26+ checks, fallback UI, NLEmbeddingGenerator, local tool invocation, privacy/offline UX. DO NOT USE FOR: source-generated tools, cloud-only AI, UI debugging.
deploy-edge-ai-model
Deploy machine learning models to edge devices using Google AI Edge Gallery, TensorFlow Lite, ONNX Runtime, and MediaPipe. Covers model quantization (INT8/INT4), on-device inference with Gemma 4 models, Android/iOS deployment via AI Edge Gallery, hardware delegate selection (GPU/NPU/DSP), and performance benchmarking…
vision-framework
On-device image analysis for an iOS fintech app with Apple's Vision + VisionKit. Covers the modern Swift Vision API (iOS 18+: RecognizeTextRequest OCR, DetectFaceRectanglesRequest, DetectBarcodesRequest, DetectDocumentSegmentationRequest, GenerateForegroundInstanceMaskRequest, TrackObjectRequest, CoreMLRequest, all…
apple-on-device-ai
On-device generative AI on Apple platforms (iOS 26+) — the Foundation Models framework (SystemLanguageModel.availability, LanguageModelSession, respond(to:)/streamResponse, @Generable + @Guide guided generation, the Tool protocol for tool-calling, instructions, GenerationOptions, and Guardrails), plus choosing among…
coreml
On-device ML inference with Core ML on iOS/iPadOS 26. Covers model formats (.mlmodel/.mlpackage/.mlmodelc), the Xcode auto-generated model class + Input/Output, MLModel loading (async load / compileModel), MLFeatureProvider / MLFeatureValue, MLModelConfiguration.computeUnits…
ipaship-audit
Use when auditing iOS/Android app submissions for compliance with Apple App Store Review Guidelines or Google Play Developer Policies. Scan .ipa, .apk, or .zip files against official store policies, generate structured compliance reports, and identify violations with remediation steps.