TanStack AI Middleware
Adds middleware to TanStack AI chat for analytics, logging, tool caching and tracing across its lifecycle.
Claude's review
7/10 Deep TanStack AI middleware reference with a full hook table and phase behaviour.
We asked Claude the question you would ask: would I be glad I installed this? Two separate reviews, the second blind to the first, must both rate a skill 7 or higher before we sell it.
In detail
Chat lifecycle middleware hooks: onConfig, onStart, onChunk, onBeforeToolCall, onAfterToolCall, onUsage, onFinish, onAbort, onError. Use for analytics, event firing, tool caching (toolCacheMiddleware), logging, and tracing. Middleware array in chat() config, left-to-right execution order. NOT onEnd/onFinish callbacks on chat() — use middleware.
How you use it
- Add it to your pack, then download your pack (1 credit).
- In Claude, open Customize > Skills and upload the zip. Code execution needs to be on under Settings > Capabilities.
- Ask Claude for the job in your own words. It uses the skill when your request matches what it does. Step by step guide
Safety check
Nothing risky found: no hidden instructions, no download and run, no reading of saved passwords or keys.
An automated scan lowers risk but cannot promise zero risk. How we check skills
Preview
The first lines of SKILL.md
---
name: ai-core/middleware
description: >
Chat lifecycle middleware hooks: onConfig, onStart, onChunk,
onBeforeToolCall, onAfterToolCall, onUsage, onFinish, onAbort, onError.
Use for analytics, event firing, tool caching (toolCacheMiddleware),
logging, and tracing. Middleware array in chat() config, left-to-right
execution order. NOT onEnd/onFinish callbacks on chat() — use middleware.
type: sub-skill
library: tanstack-ai
library_version: '0.42.0'
sources:
- 'TanStack/ai:docs/advanced/middleware.md'
- 'TanStack/ai:docs/sandbox/observability.md'
- 'TanStack/ai:docs/persistence/overview.md'
---
# Middleware
> **Dependency note:** This skill builds on ai-core. Read it first for critical rules.
## Setup — Analytics Tracking Middleware
```typescript
import { chat, toServerSentEventsResponse } from '@tanstack/ai'
import { openaiText } from '@tanstack/ai-openai'
import { trackAnalytics, reportError } from './analytics'
export async function POST(request: Request) {
const { messages, threadId } = await request.json()
const stream = chat({
adapter: openaiText('gpt-5.5'),
messages,
threadId,
middleware: [
{
onStart: (ctx) => {
console.log('Chat started:', ctx.model)
},
...From TanStack's repository, MIT licence.
Related skills
-
Checked
Neuron PHP AI Agents
Builds and configures AI agents in PHP with the Neuron framework, covering tools, memory and streaming.
7/101 credit -
Checked
RAG evaluation
Measures how well a RAG system retrieves and answers, with test questions, metrics and chunking advice.
7/101 credit -
Checked
LangSmith Agent Testing
Sets up LangSmith datasets, scorers and experiments so you can prove an AI agent change is better before release.
7/101 credit -
Checked
Test and Fix Loop
Sets up a coding agent to run tests, read failures and fix them until green, with a safe point to stop.
8/101 credit -
Checked
AI Failure Analysis
Sorts real chatbot or agent logs into named failure types with counts, so you know which tests to write first.
7/101 credit -
Checked
AI Agent Eval Rubric
Writes pass or fail checks that define good behaviour for your AI agent, plus release targets for the PRD.
7/101 credit