Created
          March 28, 2025 13:59 
        
      - 
      
- 
        Save vrushankportkey/c1dc4974da35ef82076e41bab2ccac3d to your computer and use it in GitHub Desktop. 
    Using Portkey in Langchain to call Gemini API
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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