
Pinme Llm
- 425 installs
- 3.7k repo stars
- Updated July 25, 2026
- glitternetwork/pinme
pinme-llm is a PinMe agent skill that teaches correct TypeScript Worker code for OpenRouter-backed chat/completions, streaming, models, and web search via the PinMe proxy without exposing real OpenRouter API keys.
About
pinme-llm is an agent skill for PinMe Worker TypeScript projects that need OpenRouter LLM access through PinMe's hosted proxy at pinme.cloud. Workers authenticate with an injected API_KEY and PROJECT_NAME—never the raw OpenRouter key—and call GET /api/v1/models or POST /api/v1/chat/completions with optional SSE streaming and openrouter:web_search tools. The SKILL.md documents a 1MB request body limit, PinMe error codes from 401 through 502, and copy-paste helpers like extractPinmeOpenRouterError and callOpenRouterJSON. Developers reach for pinme-llm when adding non-streaming chat routes, SSE passthrough handlers, or web-search-augmented completions inside PinMe Workers backed by D1.
- PinMe-backed context pinning for agents
- Stable references across sessions and hosts
- Retrieval hooks for prompts and artifacts
- Fits multi-agent and CLI automation
- Reduces duplicated context payloads
Pinme Llm by the numbers
- 425 all-time installs (skills.sh)
- Ranked #1,924 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/glitternetwork/pinme --skill pinme-llmAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 425 |
|---|---|
| repo stars | ★ 3.7k |
| Last updated | July 25, 2026 |
| Repository | glitternetwork/pinme ↗ |
How do PinMe Workers call OpenRouter LLM APIs safely?
Pin and retrieve LLM context, prompts, or artifacts via PinMe network primitives so distributed agents share stable references across sessions and environments.
Who is it for?
Developers building PinMe Worker TypeScript backends who need OpenRouter chat, streaming, or web search without storing provider API keys in Worker code.
Skip if: Developers not on the PinMe platform or projects that call OpenRouter directly outside PinMe's proxy and injected env contract.
When should I use this skill?
A PinMe Worker project needs OpenRouter models, chat/completions, SSE streaming, or openrouter:web_search integration code.
What you get
TypeScript Worker handlers for models listing, chat/completions, SSE streaming passthrough, web-search tool calls, and PinMe-specific error extraction patterns.
- Worker chat route handlers
- SSE streaming passthrough
- PinMe OpenRouter error extractor
By the numbers
- Documents a 1MB maximum request body size for chat/completions
- Covers HTTP error statuses 401, 400, 403, 413, 500, and 502 for proxy failures
Files
PinMe Worker OpenRouter API Integration
Guides how to call PinMe platform's OpenRouter proxy APIs in a PinMe Worker (TypeScript). Workers use the PinMe project API key; they never hold the real OpenRouter API key.
Environment Variables
The following environment variables are automatically injected when the Worker is created — no manual configuration needed:
// backend/src/worker.ts
export interface Env {
DB: D1Database;
API_KEY: string; // Project API Key from create_worker
PROJECT_NAME: string; // Actual project_name from create_worker; must match API_KEY
BASE_URL?: string; // Optional override for PinMe API base URL, defaults to https://pinme.cloud
}API_KEYauthenticates the Worker to PinMe.PROJECT_NAMEis required forchat/completionsand must belong to the same project asAPI_KEY. WhenBASE_URLis not set, usehttps://pinme.cloud.
---
Models API
Endpoint: GET {BASE_URL}/api/v1/models Authentication: X-API-Key header (using env.API_KEY) Request Body: none
Use this when the Worker needs to list available OpenRouter models. The response body, status, and headers are passed through from OpenRouter /models.
async function listModels(env: Env): Promise<unknown> {
const baseUrl = env.BASE_URL ?? 'https://pinme.cloud';
const resp = await fetch(`${baseUrl}/api/v1/models`, {
headers: { 'X-API-Key': env.API_KEY },
});
if (!resp.ok) {
throw new Error(await extractPinmeOpenRouterError(resp));
}
return await resp.json();
}---
Chat Completions API
Endpoint: POST {BASE_URL}/api/v1/chat/completions?project_name={project_name} Authentication: X-API-Key header (using env.API_KEY) Request Body: OpenRouter chat/completions format, passed through as-is after a 1MB size check Streaming: Supports SSE (stream: true) Web Search: Supports OpenRouter openrouter:web_search server tool via the tools array
Request Format
{
"model": "openai/gpt-4o-mini",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Hello!" }
],
"stream": true
}Useenv.PROJECT_NAMEfromcreate_worker; always URL-encode it in the query string. For available models, callGET /api/v1/modelsor refer to OpenRouter model IDs.
OpenRouter Web Search
PinMe does not provide a raw search endpoint. To search the web, pass OpenRouter's openrouter:web_search server tool to chat/completions; the model decides whether and when to search.
Always set max_results and max_total_results to keep search volume and cost bounded.
async function searchWithLLM(env: Env, query: string): Promise<string> {
const baseUrl = env.BASE_URL ?? 'https://pinme.cloud';
const resp = await fetch(
`${baseUrl}/api/v1/chat/completions?project_name=${encodeURIComponent(env.PROJECT_NAME)}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': env.API_KEY,
},
body: JSON.stringify({
model: 'openai/gpt-5.2',
messages: [{ role: 'user', content: query }],
tools: [
{
type: 'openrouter:web_search',
parameters: {
engine: 'auto',
max_results: 5,
max_total_results: 10,
},
},
],
}),
},
);
if (!resp.ok) {
throw new Error(await extractPinmeOpenRouterError(resp));
}
const data = await resp.json() as { choices: Array<{ message?: { content?: string } }> };
return data.choices[0]?.message?.content ?? '';
}Response Format
Successful requests return OpenRouter's raw response body.
Non-streaming Success (200):
{
"id": "chatcmpl-...",
"choices": [{ "message": { "role": "assistant", "content": "Hello!" }, "finish_reason": "stop" }],
"usage": { "prompt_tokens": 10, "completion_tokens": 5, "total_tokens": 15 }
}Streaming Success (200): SSE format
data: {"choices":[{"delta":{"content":"Hello"}}]}
data: {"choices":[{"delta":{"content":" there"}}]}
data: [DONE]Errors:
| HTTP Status | Meaning | data.error Example |
|---|---|---|
| 401 | API Key missing, invalid, or mismatched with project_name | "X-API-Key header is required" / "Invalid API key" / "Invalid API key or project name" |
| 400 | project_name missing or OpenRouter key not configured | "project_name is required" / "LLM service not configured for this project" |
| 403 | LLM balance insufficient or disabled | "Insufficient balance, please recharge to continue using LLM service" |
| 413 | Request body exceeds 1MB | "Request body too large (max 1MB)" |
| 500 | Proxy failed before upstream request | "Failed to build request" |
| 502 | LLM service unavailable | "LLM service unavailable" |
If OpenRouter receives the request and returns a 4xx/5xx, PinMe passes through OpenRouter's status, headers, and response body instead of wrapping it.
Worker Example Code — Non-streaming
async function callLLM(
env: Env,
messages: Array<{ role: string; content: string }>,
model = 'openai/gpt-4o-mini',
): Promise<{ content: string; error?: string }> {
const baseUrl = env.BASE_URL ?? 'https://pinme.cloud';
const resp = await fetch(
`${baseUrl}/api/v1/chat/completions?project_name=${encodeURIComponent(env.PROJECT_NAME)}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': env.API_KEY,
},
body: JSON.stringify({ model, messages }),
},
);
if (!resp.ok) {
return { content: '', error: await extractPinmeOpenRouterError(resp) };
}
const data = await resp.json() as { choices: Array<{ message: { content: string } }> };
return { content: data.choices[0]?.message?.content || '' };
}
// Usage in routes
async function handleChat(request: Request, env: Env): Promise<Response> {
const { question } = await request.json() as { question: string };
const result = await callLLM(env, [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: question },
]);
if (result.error) {
return json({ error: result.error }, 502);
}
return json({ answer: result.content });
}Worker Example Code — Streaming (SSE Passthrough)
async function handleChatStream(request: Request, env: Env): Promise<Response> {
const body = await request.text();
const baseUrl = env.BASE_URL ?? 'https://pinme.cloud';
// Ensure stream=true in the request
let parsed = JSON.parse(body);
parsed.stream = true;
const resp = await fetch(
`${baseUrl}/api/v1/chat/completions?project_name=${encodeURIComponent(env.PROJECT_NAME)}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': env.API_KEY,
},
body: JSON.stringify(parsed),
},
);
if (!resp.ok) {
return json({ error: await extractPinmeOpenRouterError(resp) }, resp.status);
}
// Pass through SSE stream directly
return new Response(resp.body, {
status: 200,
headers: {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
...CORS_HEADERS,
},
});
}Frontend SSE Stream Consumer Example
async function streamChat(question: string, onChunk: (text: string) => void): Promise<void> {
const resp = await fetch(getApiUrl('/api/chat/stream'), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ question }),
});
const reader = resp.body!.getReader();
const decoder = new TextDecoder();
let buffer = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const lines = buffer.split('\n');
buffer = lines.pop()!; // Keep incomplete line
for (const line of lines) {
if (!line.startsWith('data: ')) continue;
const payload = line.slice(6);
if (payload === '[DONE]') return;
const chunk = JSON.parse(payload) as { choices: Array<{ delta: { content?: string } }> };
const content = chunk.choices[0]?.delta?.content;
if (content) onChunk(content);
}
}
}---
Error Handling Pattern
For /api/v1/models and /api/v1/chat/completions, successful responses are raw OpenRouter responses. Proxy failures before the OpenRouter request use PinMe's wrapped error format:
interface PinmeResponse<T = unknown> {
code: number; // 200=success, other=failure
msg: string; // "ok" | "error" | "invalid params"
data?: T; // Business data on success, may contain { error: string } on failure
}Recommended Error Extractor
async function extractPinmeOpenRouterError(resp: Response): Promise<string> {
const fallback = `HTTP ${resp.status}`;
try {
const body = await resp.clone().json() as PinmeResponse | { error?: { message?: string } } | { error?: string };
if ('data' in body && body.data && typeof body.data === 'object' && 'error' in body.data) {
return String((body.data as { error: unknown }).error);
}
if ('msg' in body && typeof body.msg === 'string' && body.msg) {
return body.msg;
}
if ('error' in body) {
const error = body.error;
if (typeof error === 'string') return error;
if (error && typeof error === 'object' && 'message' in error) {
return String((error as { message: unknown }).message);
}
}
} catch {
try {
const text = await resp.text();
if (text) return text;
} catch {
// Ignore and return fallback below.
}
}
return fallback;
}Optional JSON Helper
Use this helper for non-streaming POST calls. It returns the raw OpenRouter JSON on success.
async function callOpenRouterJSON<T>(url: string, apiKey: string, body: unknown): Promise<{ data?: T; error?: string }> {
let resp: Response;
try {
resp = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-API-Key': apiKey },
body: JSON.stringify(body),
});
} catch {
return { error: 'Network error' };
}
if (!resp.ok) {
return { error: await extractPinmeOpenRouterError(resp) };
}
return { data: await resp.json() as T };
}Usage Example
const baseUrl = env.BASE_URL ?? 'https://pinme.cloud';
// Call LLM (non-streaming)
const llmResult = await callOpenRouterJSON<{ choices: Array<{ message: { content: string } }> }>(
`${baseUrl}/api/v1/chat/completions?project_name=${encodeURIComponent(env.PROJECT_NAME)}`, env.API_KEY,
{ model: 'openai/gpt-4o-mini', messages: [{ role: 'user', content: 'Hi' }] },
);
if (llmResult.error) return json({ error: llmResult.error }, 502);Related skills
How it compares
Pick pinme-llm over generic OpenRouter guides when building inside PinMe Workers that must use the platform proxy, injected env vars, and project-scoped authentication.
FAQ
Does pinme-llm require an OpenRouter API key in Worker code?
pinme-llm instructs Workers to use PinMe-injected API_KEY and PROJECT_NAME env vars against the PinMe proxy. Workers never store the real OpenRouter API key; PinMe handles upstream authentication on the developer's behalf.
Which PinMe endpoints does pinme-llm cover?
pinme-llm documents GET /api/v1/models for listing OpenRouter models and POST /api/v1/chat/completions with optional stream:true SSE and openrouter:web_search tools. Requests authenticate via the X-API-Key header and URL-encoded project_name query parameter.
How does pinme-llm handle streaming responses?
pinme-llm shows Workers setting stream:true on chat/completions and passing the upstream SSE body through with text/event-stream headers. A frontend consumer example parses data: lines and terminates on the [DONE] sentinel.