plaingateway
Features

Prompt caching

Reuse a long prompt prefix at the cached token price.

A cache read is an input token the host served from its cache, at the lower input_cache_read price. A cache write is an input token the host stored for later, at the input_cache_write price. Both prices are in GET /models. A cache lives on one host, so the gateway sends a model's requests to the same first host each time (host pinning).

Anthropic models

Mark the end of the part to cache with cache_control in a Messages request. cache_control works only on an Anthropic host, and the model must be one an AI provider key serves. Today no key serves an anthropic/ model, so put in a model ID once one is served:

sh
curl https://api.plaingateway.com/api/v1/messages \
  -H "x-api-key: $PLAINGATEWAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "<a served Anthropic model ID>", "max_tokens": 64, "system": [{"type": "text", "text": "<a long document>", "cache_control": {"type": "ephemeral"}}], "messages": [{"role": "user", "content": "Summarize it."}]}'

usage.cache_creation_input_tokens counts tokens written and usage.cache_read_input_tokens counts tokens read. cache_control on chat completions content parts is passed to Anthropic hosts too.

Other models

OpenAI hosts cache long prompts on their own. usage.prompt_tokens_details.cached_tokens counts the cached input tokens.