Sign in Get 3 free credits

Try a job or a niche: tiktok captions, study notes, excel formulas. Press Esc to close.

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

  1. Add it to your pack, then download your pack (1 credit).
  2. In Claude, open Customize > Skills and upload the zip. Code execution needs to be on under Settings > Capabilities.
  3. 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.

    by neuron-core 2.2k
    7/101 credit
  • Checked

    RAG evaluation

    Measures how well a RAG system retrieves and answers, with test questions, metrics and chunking advice.

    by ai-evals-course 1.9k
    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.

    by langchain-ai 1.4k
    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.

    by agentsope 513
    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.

    by yonatangross 312
    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.

    by Calibre-Labs 107
    7/101 credit

Secure checkout

Credits

AUD

  1. 1Choose
  2. 2Pay on Square
  3. 3Credits added