Welcome to Portkey Forum

Updated 2 months ago

Gemini with Langchain

At a glance

A community member is having trouble getting Portkey to work with LangChain for Google's models. They have provided a sample code snippet and mentioned that they have attached a traceback. The community member has also confirmed that they are using the latest versions of the required packages.

Another community member has responded, asking the original poster to confirm if their Google or Vertex API key is valid and working when making a direct call to Google or Vertex. The original poster has responded, saying they have fixed the issue.

Hey, I cannot seem to get portkey to work with langchain for google's models.
This is a sample of what I am using
Plain Text
from langchain_openai import ChatOpenAI
from portkey_ai import createHeaders, PORTKEY_GATEWAY_URL

PORTKEY_API_KEY = "..."
VIRUTAL_KEY = "..." # Virtual Key I created

portkey_headers = createHeaders(api_key=PORTKEY_API_KEY,virtual_key= VIRUTAL_KEY)

llm = ChatOpenAI(api_key="x", base_url=PORTKEY_GATEWAY_URL, default_headers=portkey_headers, model="gemini-1.5-pro")

llm.invoke("What is the meaning of life, universe and everything?")


I have attached the trace back.
I am on the latest version of all the packages as I ran pip install -U langchain-core portkey_ai langchain-openai before starting
s
H
2 comments
Hey @Harold Senzei I tried to replicate this error, but I was not able to, can you confirm for me if your google or vertex api key is valid and works when you make a call directly to goole or vertex?
Sorry for the delay, I fixed it
Add a reply
Sign up and join the conversation on Discord