C.W.K.
Stream
Lesson 03 of 05 · published

Provider 차이, Provider 숭배 X

~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

같은 idea, 다른 손잡이

OpenAI prompt caching은 적합 prompt에 자동, usage에 cached_tokens 노출. Anthropic은 명시적 cache_control breakpoint 사용, cache_creation_input_tokenscache_read_input_tokens 보고. Gemini는 implicit/explicit context caching 자체 token threshold + TTL behavior.

Portable idea, provider-specific 구현

Portable idea는 stable prefix 재사용. Provider-specific 구현 변함. 앱은 idea 중심으로 설계, adapter layer를 provider에 adapt. 한 provider caching mechanism hardcode하는 앱은 두 번째 추가하면 매우 awkward.

Abstraction을 정직하게

Provider detail 다 숨기지 마. Telemetry는 어느 provider, model, cache mode, cached token count 썼는지 기록. 차이 존재; 없는 척하면 최악의 버그 생성 — provider A엔 작동, B엔 silently 실패.

Code

Provider-neutral cache telemetry·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"
Adapter layer 스케치·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 object 설계.
Hint
Provider-specific field는 optional detail로, core abstraction X.

Progress

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

댓글 0

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

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