Native Messages API, not a translation layer
PALM SOUQ proxies the Anthropic Messages API in its native format at gateway.palmsouqltd.com/anthropic. Nothing is converted to an OpenAI shape and back, so tool use blocks, extended thinking, citations and beta headers reach Anthropic unchanged. You set base_url on the official Python or TypeScript SDK, add your PALM SOUQ key and tenant headers, and keep your Anthropic API key where it is.
Streaming responses are relayed event by event. The gateway reads message_start and message_delta events in flight to keep a running token count for the session, which is what the token velocity heuristic watches, and finalises cost when message_stop arrives.
Cache accounting that matches the invoice
Claude prompt caching has three input prices. A cache write costs 1.25x the base input rate for the default five-minute cache, a cache read costs 0.1x, and everything after the last cache breakpoint is billed at the normal input rate. Anthropic returns these as cache_creation_input_tokens, cache_read_input_tokens and input_tokens on every response.
PALM SOUQ prices each of the three separately against the rates in the PALM SOUQ price table, then attributes them to the tenant, feature and prompt template. That matters because the tenant that pays the write premium is often not the tenant that enjoys the reads. Without the split, a shared system prompt makes one customer look expensive and the rest look cheap.
Breakers and fallbacks for Claude agents
Claude is a common choice for agent loops, and agent loops are where runaway spend happens. The cyclical tool thrashing heuristic hashes each tool_use block's name and input, so an agent that calls the same search tool with the same query fifteen times is cut off on the fifteenth call. Step depth caps count assistant turns per session id.
Fallback chains work across the Claude family: Sonnet 4.5 to Haiku 4.5 when a tenant passes 90% of budget, or to a cached response for repeated read-only queries. Because the gateway speaks the Messages format on both sides, the fallback is invisible to your code.
Rolling it out safely
Start with the client that has the largest cached system prompt, because that is where per-tenant cache accounting changes your margin numbers most. Run it through the gateway in staging and compare the cache write and read totals for a day against the Anthropic console usage page.
Then enable observe mode on the tool thrashing and step depth heuristics for your agent sessions. A week of would-have-tripped events tells you whether the default thresholds of 15 repeats and 40 steps suit your agents before you enforce them in production.