How to Set Up Groq API Integration for AI-Powered Features in LazyOwn

Export your Groq API key as GROQ_API_KEY and run the groq command inside LazyOwn to generate AI-powered shell commands instantly.

LazyOwn is an open-source penetration testing framework that ships with native support for Groq's large language models. The Groq API integration enables AI-powered command generation, allowing security professionals to convert natural language prompts into executable shell commands without leaving the terminal environment.

Installation and Prerequisites

The groq Python package is declared as a dependency in both setup.py and pyproject.toml within the LazyOwn repository. The framework provides an automated installation script that handles the dependency resolution.

Run the installation script from the LazyOwn root directory:

./install.sh

Alternatively, install the Groq client manually using pip:

pip3 install groq

Configuring Your API Key

All entry points in LazyOwn—including the interactive console, CLI helpers, and the model abstraction layer—read the API key from the GROQ_API_KEY environment variable. Export this variable in your shell before launching LazyOwn:

export GROQ_API_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxx"

In lazyown.py, the do_groq method (lines 25838‑L25860) automatically injects this environment variable into subprocess calls that execute the Groq CLI helpers. If the variable is missing, the scripts abort with a clear error message, as implemented in modules/lazygptcli2.py (lines 36‑40).

Using the Groq Integration

LazyOwn exposes the Groq integration through three distinct interfaces: an interactive console command, a standalone CLI utility, and a programmatic Python API.

Interactive Console Method

Start the main LazyOwn console and invoke the built-in groq command:

python3 lazyown.py

Inside the console, type natural language prompts:

groq list open ports on 192.168.1.5

Behind the scenes, the do_groq method sets the environment variable and executes modules/lazygptcli2.py, which formats the prompt and streams the response from Groq's API.

Standalone CLI Execution

You can run the CLI helper directly without entering the interactive console. This is useful for automation scripts or one-off command generation:

export GROQ_API_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
python3 modules/lazygptcli2.py \
    --prompt "create a bash one-liner that extracts all URLs from a file" \
    --debug

The create_complex_prompt function concatenates your input with any knowledge-base context before sending it to the Groq client. The response is printed with the prefix [R] Respuesta: followed by the generated command (lines 36‑46 in lazygptcli2.py).

Programmatic Usage via GroqModel

For custom modules or scripts extending LazyOwn, import the GroqModel class from the abstraction layer:

import os
from modules.ai_model import GroqModel

# Initialize with your API key

model = GroqModel(api_key=os.getenv("GROQ_API_KEY"))

# Generate a command

result = model.generate("Write a PowerShell one-liner that lists running services")
print(result)

The GroqModel class (defined in modules/ai_model.py, lines 20‑47) exposes two primary methods: generate() for synchronous responses and stream_generate() for streaming output. This abstraction allows seamless switching to local Ollama models by substituting OllamaModel without changing the calling code.

Architecture Overview

The Groq integration in LazyOwn follows a three-layer architecture that separates configuration, interface, and implementation concerns:

  • Environment Configuration Layer: Located in lazyown.py, the do_groq command manages the GROQ_API_KEY environment variable and orchestrates the execution of helper scripts.

  • CLI Helper Layer: The modules/lazygptcli2.py script handles prompt construction, API communication via client.chat.completions.create, and response formatting.

  • Model Abstraction Layer: The GroqModel class in modules/ai_model.py wraps the official groq Python client, standardizing the interface with generate and stream_generate methods. By default, LazyOwn uses the llama3-70b-8192 model, as specified in modules/lazysearch_bot.py (line 44).

This design allows you to swap between cloud-based Groq inference and local Ollama instances simply by changing the model class instantiation, while the rest of the framework remains provider-agnostic.

Summary

  • Install dependencies using ./install.sh or pip3 install groq to satisfy requirements declared in setup.py and pyproject.toml.
  • Export GROQ_API_KEY in your shell environment; all LazyOwn components read this variable via os.environ.
  • Use interactively via the groq command inside lazyown.py, which triggers do_groq (lines 25838‑L25860).
  • Run standalone by executing modules/lazygptcli2.py directly for command-line automation.
  • Integrate programmatically using the GroqModel class in modules/ai_model.py (lines 20‑47) for custom module development.
  • Switch providers seamlessly by substituting OllamaModel for GroqModel without refactoring calling code.

Frequently Asked Questions

What environment variable does LazyOwn use for the Groq API key?

LazyOwn exclusively uses GROQ_API_KEY. This variable is read by the interactive console in lazyown.py, the CLI helpers in modules/lazygptcli2.py, and the GroqModel class in modules/ai_model.py. If the variable is unset, the scripts exit with an error message indicating the missing configuration.

Can I use a local AI model instead of Groq in LazyOwn?

Yes. The framework provides an OllamaModel class in modules/ai_model.py that implements the same interface (generate and stream_generate) as GroqModel. You can instantiate OllamaModel instead of GroqModel to route requests to a local Ollama instance, enabling offline operation without modifying the rest of your code.

What is the default Groq model used by LazyOwn?

By default, LazyOwn uses the llama3-70b-8192 model. This default is defined in modules/lazysearch_bot.py at line 44. You can override this by modifying the model parameter passed to GroqModel or by adjusting the CLI helper arguments.

Where is the GroqModel class defined?

The GroqModel class is defined in modules/ai_model.py between lines 20 and 47. This file serves as the abstraction layer for all AI providers in LazyOwn, containing both the Groq and Ollama implementations with standardized method signatures for text generation.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →