Optimize JSON property order for prompt caching
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 1.5k
- Forks
- 264
- Avg merge
- 9h 46m
- Merged PRs (30d)
- 96
Description
Context/motivation: ability to reduce costs while using the APIs via this SDK.
In order to increase the chances of prompts hitting the cache, OpenAI suggests the following:
As far as I understand, and based on experimentation and monitoring, caching works for the entirety of the content passed onto the LLM, and the structure of this content is inherited from the structure of the request body JSON.
While debugging the SDK I have found out that there is no straightforward way to control the structure of Responses API requests.
Example:
- Developer message (static)
- User message (static)
- User message (dynamic)
- Structured outputs schema (static)
Alternative structure to maximize the probability of cache hits:
- Structured outputs schema (static)
- Developer message (static)
- User message (static)
- User message (dynamic)
I have tried to call .text() function on ResponseCreateParams after everything else but it has no effect on the resulting request body.
Can there be a workaround or even functionality for this?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing ResponseCreateParams and the effect of calling its .text() function when constructing Responses API request bodies. Define how callers would control property ordering, then verify that the resulting JSON places static content before dynamic content and supports the stated prompt-caching goal.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100