본문 바로가기
C.W.K.
Stream
Lesson 03 of 05 · published

Provider 차이는 보되, Provider를 숭배하지 마

~26 min · openai, anthropic, gemini, portability

Level 0Window Watcher
0 XP0/50 lessons0/13 achievements
0/100 XP to next level100 XP to go0% complete

같은 생각, 다른 손잡이

OpenAI는 조건이 맞는 prompt면 알아서 caching을 걸고, usage에 cached_tokens를 보여줘. Anthropic은 cache_control breakpoint를 직접 찍게 하고, cache_creation_input_tokenscache_read_input_tokens를 따로 알려주고. Gemini는 암묵과 명시 두 방식을 두면서 자기만의 token 문턱이랑 TTL 규칙을 가져.

생각은 옮겨 다니고, 구현은 안 옮겨 다녀

어디서든 통하는 생각은 "stable prefix를 다시 쓴다"야. 그걸 어떻게 시키느냐는 provider마다 달라지고. 그러니까 앱은 생각을 중심에 놓고 짜고, provider 쪽은 얇은 층을 하나 두고 거기서 맞춰. 한 provider의 caching 방식을 코드에 박아넣은 앱은 두 번째를 붙일 때 아주 곤란해져.

추상화는 정직하게

provider 차이를 전부 감추려고 하지 마. 어떤 provider와 model을 썼는지, cache를 어떤 방식으로 걸었는지, cached token이 몇 개였는지 기록에 남겨. 차이는 실제로 있어. 없는 척하면 제일 고약한 버그가 태어나 — A에서는 되는데 B에서는 소리 없이 안 되는 버그.

Code

provider 안 가리는 cache 기록·yaml
cache_report:
  provider: "openai | anthropic | gemini"
  model: "..."
  cache_mode: "automatic | breakpoint | explicit"
  fresh_input_tokens: 0
  cached_input_tokens: 0
  ttl_seconds: null
  prefix_version: "rules-v3"
맞춰주는 층 스케치·python
class CacheAdapter:
    def attach_cache_breakpoint(self, content_block): ...
    def parse_cache_usage(self, response) -> dict: ...

class AnthropicAdapter(CacheAdapter):
    def attach_cache_breakpoint(self, block):
        block["cache_control"] = {"type": "ephemeral"}
        return block
    def parse_cache_usage(self, response):
        u = response.usage
        return {"cached": u.cache_read_input_tokens,
                "created": u.cache_creation_input_tokens}

External links

Exercise

OpenAI, Anthropic, Gemini를 다 똑같은 척하지 않으면서 셋 다 담을 수 있는 cache telemetry 구조를 설계해봐.
Hint
provider마다 다른 항목은 선택적인 세부로 두고, 핵심 뼈대 자리에는 올리지 마.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.