mirror of
				https://github.com/hwchase17/langchain.git
				synced 2025-10-29 23:00:18 +00:00 
			
		
		
		
	Co-authored-by: jacoblee93 <jacoblee93@gmail.com> Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
		
			
				
	
	
		
			20 lines
		
	
	
		
			598 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			20 lines
		
	
	
		
			598 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| First we'll need to install their Python package:
 | |
| 
 | |
| ```bash
 | |
| pip install openai
 | |
| ```
 | |
| 
 | |
| Accessing the API requires an API key, which you can get by creating an account and heading [here](https://platform.openai.com/account/api-keys). Once we have a key we'll want to set it as an environment variable by running:
 | |
| 
 | |
| ```bash
 | |
| export OPENAI_API_KEY="..."
 | |
| ```
 | |
| 
 | |
| If you'd prefer not to set an environment variable you can pass the key in directly via the `openai_api_key` named parameter when initiating the OpenAI LLM class:
 | |
| 
 | |
| ```python
 | |
| from langchain.llms import OpenAI
 | |
| 
 | |
| llm = OpenAI(openai_api_key="...")
 | |
| ```
 |