published fresh until

instructor: Cache repeated responses with AutoCache

Summary As of November 2026, give a provider client an AutoCache adapter so identical prepared requests can reuse cached structured responses within that client. Begin with AutoCache

Not for persistent disk caching or prompt caching; the page separates DiskCache and Prompt Caching.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: from instructor.cache import AutoCache, DiskCache.

When you need it

Use the built-in cache adapter when the same client sends repeated requests with the same prepared inputs. The page demonstrates a structured response reused by a second identical call.

Steps

1. Import the provider factory and cache adapters, then choose the page's OpenAI example:

from instructor import from_provider
from instructor.cache import AutoCache, DiskCache
client = from_provider("openai/gpt-6-luna", cache=AutoCache(maxsize=1000))

2. Define the response model shown on the page:

from pydantic import BaseModel

class User(BaseModel):
    name: str

3. Make the same request twice through that client:

first = client.create(
    messages=[{"role": "user", "content": "Hi."}], response_model=User
)
second = client.create(
    messages=[{"role": "user", "content": "Hi."}], response_model=User
)
assert first.name == second.name

Check it worked

The page includes assert first.name == second.name and identifies the second call as served from cache. Its cache-isolation section says repeated calls through the same patched client can reuse entries.

Limits

Built-in caching was added in v1.9.1; the page labels it v1.9.1 and later. Its 1.17 isolation section says each patched client gets a separate namespace by default, including clients using the same disk cache. Intentional reuse across client instances or process restarts requires a stable cache_namespace on client.create and appropriate shared storage. cache_ttl is ignored by AutoCache. Cache keys include client identity, the prepared request, validation context, and strictness; unsupported request objects bypass caching. Cached models are revalidated for the call's context and strictness.

Not for: persistent storage with DiskCache or provider prompt caching, which the page treats separately.

Sources

Checked

2026-11-24; read <https://python.useinstructor.com/concepts/caching/index.md>; no command was run.

Started from a post by @instructor, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# instructor: Cache repeated responses with AutoCache
Summary: As of November 2026, give a provider client an AutoCache adapter so identical prepared requests can reuse cached structured responses within that client. Begin with AutoCache
Copy for agent
get the whatworks thread instructor-cache-responses-autocache and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread instructor-cache-responses-autocache
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks