Welcome to Portkey Forum

Updated 3 weeks ago

Chat Completions Call to Together AI

I am making an chat completions call to Together AI

Plain Text
import Portkey from "portkey-ai";

let portkey = new Portkey({
  apiKey: process.env.PORTKEYAI_API_KEY,
  virtualKey: process.env.TOGETHERAI_API_KEY,
});

try {
  var response = await portkey.chat.completions.create({
    messages,
    model: "togethercomputer/llama-2-70b-chat",
  });
  console.info("Success", response);
} catch (error) {
  console.error("We saw errors getting response from LLM", error);
}

and I see this error:
Plain Text
error: Either x-portkey-config or x-portkey-provider header is required
      at new APIError (/Users/saifas/PKey/cookbook/scripts/node_modules/portkey-ai/dist/src/error.js:7:8)
      at new BadRequestError (/Users/saifas/PKey/cookbook/scripts/node_modules/portkey-ai/dist/src/error.js:78:8)
      at generate (/Users/saifas/PKey/cookbook/scripts/node_modules/portkey-ai/dist/src/error.js:25:19)
      at /Users/saifas/PKey/cookbook/scripts/node_modules/portkey-ai/dist/src/baseClient.js:118:22
      at fulfilled (/Users/saifas/PKey/cookbook/scripts/node_modules/portkey-ai/dist/src/baseClient.js:5:47)

I don't usually see this error when making API calls to OpenAI. Should we add config or provider explicitly?
S
V
v
6 comments
This is solved. I first tried provider property. Later discovered, my ENV virtual is not being substituted properly.
Thanks! Looks like we should send a better error message here. cc @visarg

Should the error here be something like, "Your Virtual key is wrong"?
We already throw proper error if the virtual key is actually wrong. But if its undefined/empty, then we skip the check and move on to the next step of validation because portkey also allows calls without virtual key. I think in this case virtual key was being set as undefined/empty so we were not able to check it.
Example message that we send on wrong virtual key:
Plain Text
{
    "status": "failure",
    "message": "Following keys are not valid: <key-name-1>, <key-name-2>,..."
}
Awesome, thanks for sharing πŸ™Œ
I think in this case virtual key was being set as undefined/empty so we were not able to check it.

Some error messages straight away include questions such as, "Are you sure the virtual key is properly substituted?"

That's one idea that you can maybe consider. It is not as strict to tell the user the cause, but just a hint to look at perhaps the right place.
Add a reply
Sign up and join the conversation on Discord