Get up and running with the Groq API in a few minutes.
Please visit here to create an API Key.
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.
export GROQ_API_KEY=<your-api-key-here>
pip install groq
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="llama-3.3-70b-versatile",
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.