Skip to content

Instantly share code, notes, and snippets.

@vrushankportkey
Created March 28, 2025 13:59
Show Gist options
  • Save vrushankportkey/c1dc4974da35ef82076e41bab2ccac3d to your computer and use it in GitHub Desktop.
Save vrushankportkey/c1dc4974da35ef82076e41bab2ccac3d to your computer and use it in GitHub Desktop.
Using Portkey in Langchain to call Gemini API
from langchain_openai import ChatOpenAI
from portkey_ai import createHeaders, PORTKEY_GATEWAY_URL
portkey_headers = createHeaders(
api_key="YOUR_PORTKEY_API_KEY",
config={
"virtual_key":"YOUR_GOOGLE_AI_STUDIO_VIRTUAL_KEY",
"override_params":{
"model":"gemini-1.5-pro-latest"
}
}
)
llm = ChatOpenAI(
api_key="xx", # Passing a dummy value here
base_url=PORTKEY_GATEWAY_URL,
default_headers=portkey_headers
)
llm.invoke("What is the meaning of life, universe and everything?")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment