Welcome to the Groq Security Onboarding guide.
This page walks through best practices for protecting your API keys, securing client configurations, and hardening integrations before moving into production.Security is a shared responsibility between Groq and our customers.
While Groq ensures secure API transport and service isolation, customers are responsible for securing client-side configurations, keys, and data handling.All Groq API traffic is encrypted in transit using TLS 1.2+ and authenticated via API keys.
Never expose or hardcode API keys directly into your source code.
Use environment variables or a secret management system.# Good: use environment variables
export GROQ_API_KEY="gsk_your_secret_key_here"
# Bad: avoid committing secrets to source
echo 'api_key="gsk_your_secret_key_here"' >> config.pyimport os
from groq import Groq
client = Groq(api_key=os.getenv("GROQ_API_KEY"))import { Groq } from "groq";
const client = new Groq({
apiKey: process.env.GROQ_API_KEY,
});Warning: Never embed keys in frontend code or expose them in browser bundles. If you need client-side usage, route through a trusted backend proxy.
import os
from groq import Groq
def secure_client():
key = os.getenv("GROQ_API_KEY")
if not key:
raise RuntimeError("Missing GROQ_API_KEY in environment")
return Groq(api_key=key)
client = secure_client()
print(client.models.list()) # Test callimport { Groq } from "groq";
function secureClient() {
const key = process.env.GROQ_API_KEY;
if (!key) {
throw new Error("Missing GROQ_API_KEY in environment");
}
return new Groq({ apiKey: key });
}
const client = secureClient();
console.log(await client.models.list()); // Test callGroq APIs enforce HTTPS (TLS 1.2 or higher). You should never disable SSL verification.
import requests
response = requests.get("https://api.groq.com", verify=True)const https = require("https");
https.get("https://api.groq.com", (res) => {
console.log("TLS Verified:", res.socket.authorized);
});When integrating Groq into user-facing systems, ensure that user inputs cannot trigger prompt injection or tool misuse.
Recommendations:
Implement client-side rate limiting and exponential backoff for 429 / 5xx responses.
import time, random
from groq import Groq
client = Groq(api_key="gsk_...")
for attempt in range(5):
try:
resp = client.models.list()
break
except Exception as e:
wait = min(2 ** attempt + random.random(), 30)
time.sleep(wait)async function callWithBackoff(fn, maxRetries = 5) {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn();
} catch (err) {
const delay = Math.min(2 ** i + Math.random(), 30);
await new Promise((r) => setTimeout(r, delay * 1000));
}
}
}Maintain structured logs for all API interactions.
Include:
Tip: Avoid logging sensitive data or raw model responses containing user information.
When using Groq's Tool Use or external function execution features:
import requests
from urllib.parse import quote
class SafeTools:
@staticmethod
async def get_weather(city):
url = f"https://api.weather.com?q={quote(city)}"
return requests.get(url)
# Export for use
safe_tools = SafeTools()const safeTools = {
getWeather: async (city) => fetch(`https://api.weather.com?q=${encodeURIComponent(city)}`),
};
export default safeTools;If you suspect your API key is compromised:
Warning: Never reuse compromised keys, even temporarily.
This security guide should be customized based on your specific application requirements and updated based on production learnings.