Third-party AI APIs send proprietary code off your network and make CI/CD costs scale with commit volume. By orchestrating a local model like Llama 3 via Ollama in your GitHub Actions or GitLab CI runners, you keep source code inside your own trust boundary and trade a per-token bill for fixed compute you already pay for. Keep the model size small (7B-8B parameters) so it fits in runner memory.
The Cloud API Cost Trap
When you integrate an AI code reviewer or a test generator into your CI/CD pipeline, every commit triggers a prompt. Work out your own number before you argue about the architecture: twenty developers pushing ten times a day is 200 pipeline runs per day, or roughly 4,400 per month across 22 working days. Multiply that by the tokens one review actually sends — the diff, the surrounding file context, and the model's response — and then by your provider's current per-million-token rate for input and output separately. The result is a monthly figure that grows with headcount and commit frequency, neither of which you want to discourage.
A local model moves that line item onto compute you are already paying for, so the marginal cost of the next commit is runner minutes rather than tokens. Waiting on an external network request also adds a fragile point of failure to a process that must remain deterministic.
More importantly, relying on external APIs means sending your unreleased, proprietary source code out of your network. Even with strict data processing agreements, many enterprise security teams will rightfully block this architecture.
Running Models Locally in CI
The solution is to run open-weights models directly on your build servers. Tools like Ollama allow you to spin up a model within a Docker container exactly when you need it, and tear it down when the pipeline finishes.
Step 1: Choose the Right Model Size
You cannot run a 70-billion parameter model on a standard CI runner. Choose a focused, smaller model (e.g., a 7B or 8B parameter model like Llama 3 8B or CodeQwen). A 4-bit quantized 8B model needs roughly 5–6 GB of RAM for weights plus headroom for the context window, so it fits on a 16 GB runner with room to spare and is tight but workable on 8 GB. Check your own runner tier before committing — the numbers differ by repository visibility, as the warning below explains.
Step 2: Start the Model Service in Your Pipeline
Here is an example of how you might start Ollama in a background step within your CI configuration before running your automated checks.
# Example CI step for starting a local AI service
- name: Start Ollama Background Service
run: |
docker run -d -p 11434:11434 --name ollama ollama/ollama
sleep 5 # Wait for initialization
docker exec ollama ollama pull llama3
Step 3: Query the Local Endpoint
Once the service is running, your static analysis scripts can query http://localhost:11434 just like any other API. There are no API keys required and no network egress costs.
Verification: How to Test It
To verify that your setup works correctly and securely, run a dummy pipeline job that queries the model and checks the network logs.
- Check the output: Ensure the script successfully receives a code review response from the local endpoint.
- Verify network isolation: Temporarily disable outbound internet access on the runner after the Docker image is pulled. The AI review step must still pass.
- Monitor RAM usage: Ensure the runner does not OOM (Out of Memory) crash when the model is loaded into memory. If it does, switch to a more aggressively quantized model (e.g., 4-bit quantization).
Check what your runner actually gets before you size the model. As of August 2026, GitHub's standard Linux and Windows runners provide 4 CPUs and 16 GB of RAM for public repositories, but only 2 CPUs and 8 GB for private repositories — and a private repo is exactly where proprietary code lives. An 8B model at 4-bit quantization fits in 8 GB; the same model at full precision does not. If it will not fit, configure larger runners or use self-hosted infrastructure. Running models purely on CPU without GPU acceleration will also be slower; factor this latency into your build timeouts.
For more on how to manage AI deployments in your infrastructure, see Running AI Agents in Parallel: Queueing, Locking, and Concurrency. If you are struggling with unpredictable AI behavior in your automated tests, review the AI Regression Test Plan Template.