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.

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:


import os

from groq import Groq

client = Groq(
    api_key=os.environ.get("GROQ_API_KEY"),
)

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Explain the importance of fast language models",
        }
    ],
    model="llama3-8b-8192",
)

print(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