Documentation
Quickstart
Get up and running with the Groq API in a few minutes.
Create an API Key
Please visit here to create an API Key.
Set up your API Key (recommended)
Configure your API key as an environment variable. This approach streamlines your API usage by eliminating the need to include your API key in each request. Moreover, it enhances security by minimizing the risk of inadvertently including your API key in your codebase.
In your terminal of choice:
export GROQ_API_KEY=<your-api-key-here>
Requesting your first chat completion
Install the Groq Python library:
pip install groq
Performing a Chat Completion:
1import os
2
3from groq import Groq
4
5client = Groq(
6 api_key=os.environ.get("GROQ_API_KEY"),
7)
8
9chat_completion = client.chat.completions.create(
10 messages=[
11 {
12 "role": "user",
13 "content": "Explain the importance of fast language models",
14 }
15 ],
16 model="llama3-8b-8192",
17)
18
19print(chat_completion.choices[0].message.content)
Now that you have successfully received a chat completion, you can try out the other endpoints in the API.
Next Steps
- Check out the Playground to try out the Groq API in your browser
- Join our GroqCloud developer community on Discord
- Chat with our Docs at lightning speed using the Groq API!
- Add a how-to on your project to the Groq API Cookbook