Welcome to Portkey Forum

Updated 2 weeks ago

Gemini with Langchain

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
G
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