Welcome to Portkey Forum

Updated 10 months ago

Force Refresh Cache for Chat Completions Request Using Portkey SDK

I wanted to force refresh the cache for a chat completions request using portkey sdk. I don't want to hit the cache for specific requests.
Plain Text
import { Portkey, createHeaders } from "portkey-ai";

let reqHeaders = createHeaders({
  "cache-force-refresh": true,
});
// rest
try {
  var response = await portkey.chat.completions.create(
    {
      messages,
      model: "gpt-3.5-turbo",
      stream: true,
    },
    { headers: reqHeaders }
  );
  for await (const chunk of response) {
    process.stdout.write(chunk.choices[0]?.delta?.content || "");
  }
} catch (error) {
  console.error("Errors usually happen:", error);
}

This is my logs (request):
Plain Text
  "headers": {
    "user-agent": "Bun/1.0.1",
    "x-forwarded-proto": "https",
    "x-portkey-headers": "{\"x-portkey-cache-force-refresh\":true}",
  },

Nevertheless, I see cache HITs. Any suggestions could help....
v
V
n
7 comments
Checking the issue
You need to pass the cacheForceRefresh key directly in the second argument instead of sending it inside headers.
Also, don’t need to use createHeaders if you’re already instantiating Portkey
We will fix the docs for this. There is one more way to do this. I am just verifying if that works. Will update here
Yes! Thanks for reporting. Doc fix coming soon
There is one more way to do this.
Ignore this please.
@visarg I'm trying to figure out the same from my python code. Can you give an example of how to flush cache?
Add a reply
Sign up and join the conversation on Discord