# How to Set Up FreeLLMAPI with a Coding Model Profile

> Set up FreeLLMAPI with a coding model profile to aggregate free LLMs. Route requests using auto:coding or set as active profile for automatic coding model selection in your IDE and CLI.

- Repository: [Tashfeen/freellmapi](https://github.com/tashfeenahmed/freellmapi)
- Tags: how-to-guide
- Published: 2026-08-26

---

**Create a coding-focused model profile in FreeLLMAPI to aggregate free-tier LLM providers into a prioritized fallback chain, then route requests using the `auto:coding` hint or set it as the active profile to ensure your IDE and CLI tools automatically select the best available coding models.**

FreeLLMAPI aggregates dozens of free-tier LLM providers behind a single OpenAI-compatible endpoint exposed at `http://localhost:3001/v1`. To optimize code generation tasks, you configure a specific coding model profile that strings together code-optimized models like GPT-4o Mini or Mixtral into a prioritized fallback chain. This guide demonstrates how to create, activate, and integrate that profile using the dashboard, CLI helpers, and direct API calls based on the `tashfeenahmed/freellmapi` source code.

## Understanding FreeLLMAPI Model Profiles

FreeLLMAPI implements profile-based routing through a relational schema managed in [`server/src/services/profile-models.ts`](https://github.com/tashfeenahmed/freellmapi/blob/main/server/src/services/profile-models.ts). The system stores **profiles** in the `profiles` table and links them to LLM models via the `profile_models` junction table, which defines priority ordering and enablement status. The **active profile** ID persists in the `settings` table under the key `active_profile_id`.

When a request arrives at the unified endpoint, the router inspects either the active profile or an `auto:*` routing hint passed in the model parameter. It then selects the highest-priority healthy model from that profile's chain, ensuring requests fail over automatically if a provider reaches rate limits.

## Creating a Coding-Focused Model Profile

### Install and Start the Server

Deploy the router locally using either the Docker one-liner or the development server:

```bash

# Docker installation (recommended)

curl -fsSL https://freellmapi.co/install.sh | bash

# Or run from source

npm run dev

```

This brings up the router at `http://localhost:3001` that will serve the model catalog and handle profile-based routing.

### Add Provider API Keys

Open `http://localhost:3001` and navigate to the **Keys** page. Paste your free-tier API keys from providers like OpenAI, Mistral, or Groq. The system encrypts these credentials in SQLite and mints a unified API token that grants access to the entire model catalog.

### Configure the Coding Profile via Dashboard

Navigate to **Profiles → New** in the web UI. Name the profile `coding` (or any identifier like `auto:code`). In the profile editor, drag code-optimized models—such as `gpt-4o-mini-code`, `mixtral-8x7b-instruct`, or `llama-3-8b-code`—into the enabled chain. Reorder them to establish priority; the router attempts the first model, then falls back to subsequent entries if the first is unavailable or unhealthy.

### Activate the Profile

Activate your coding profile using one of two methods:

1. **Global activation**: Click the "Set Active" button in the dashboard, which updates the `active_profile_id` entry in the `settings` table, or send a POST request to `/api/profiles/active`.
2. **Per-request routing**: Pass the profile name as a model hint (e.g., `auto:coding`) in your API calls to override the global active profile for that specific request.

## Integrating with Coding Agents and IDEs

### Python OpenAI SDK Configuration

Point the standard OpenAI client at the FreeLLMAPI router and use the `auto:coding` profile hint to ensure requests route through your code-optimized chain:

```python
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:3001/v1",
    api_key="freellmapi-your-unified-key"
)

resp = client.chat.completions.create(
    model="auto:coding",  # Uses the coding profile

    messages=[{"role": "user", "content": "Write a quicksort in Python"}],
)

print(resp.choices[0].message.content)
print("Routed via:", resp.headers.get("x-routed-via"))

```

The `x-routed-via` response header reveals which specific model in the chain actually processed the request, aiding in debugging and performance monitoring.

### CLI Agent Setup with Profile Injection

The CLI helper commands defined in [`cli/src/tools.ts`](https://github.com/tashfeenahmed/freellmapi/blob/main/cli/src/tools.ts) automate profile-aware configuration for popular coding agents. For example, the `setup-opencode` command creates a profile entry named `coding` and injects the unified API key into the child process without polluting your global shell environment:

```bash
npx freellmapi setup-opencode \
    --url http://localhost:3001 \
    --api-key <unified-key> \
    --profile coding

```

This generates a configuration where OpenCode sends requests to the FreeLLMAPI router, which then selects the best available coding model from your profile chain.

## Summary

- **Model profiles** in FreeLLMAPI define prioritized fallback chains stored across the `profiles`, `profile_models`, and `settings` tables, with lookup logic implemented in [`server/src/services/profile-models.ts`](https://github.com/tashfeenahmed/freellmapi/blob/main/server/src/services/profile-models.ts).
- Create coding-centric profiles through the dashboard by dragging code-optimized models into a prioritized list, ensuring fast response times and high-quality generation.
- Activate profiles globally by setting `active_profile_id` in the database, or invoke them per-request using the `auto:<profile-name>` routing syntax.
- Use CLI generators like `npx freellmapi setup-opencode` (defined in [`cli/src/tools.ts`](https://github.com/tashfeenahmed/freellmapi/blob/main/cli/src/tools.ts)) to inject profile configurations and unified API keys into coding agents.
- The unified endpoint at `http://localhost:3001/v1` accepts standard OpenAI-formatted requests and returns routing metadata via the `x-routed-via` header.

## Frequently Asked Questions

### What is a model profile in FreeLLMAPI?

A model profile is a named configuration stored in the `profiles` table that links to specific LLM models through the `profile_models` junction table. It defines an ordered list of models that the router attempts sequentially, enabling automatic failover if a provider is rate-limited or offline.

### How does the `auto:coding` routing hint work?

The `auto:coding` syntax tells the FreeLLMAPI router to look up the profile named `coding` in the database and select the highest-priority healthy model from that profile's chain. This hint overrides the global `active_profile_id` setting for that specific request, allowing dynamic model selection without changing configuration.

### Where are model profiles stored in FreeLLMAPI?

Model profiles persist in an SQLite database. The `profiles` table stores the profile names, while `profile_models` manages the many-to-many relationships between profiles and available models. The `settings` table tracks the `active_profile_id` that determines which profile loads by default when no explicit routing hint is provided.

### Can I switch between multiple coding profiles for different tasks?

Yes. You can create multiple profiles (e.g., `coding-fast`, `coding-smart`) via the dashboard and switch between them either by updating the active profile through the `POST /api/profiles/active` endpoint or by specifying different `auto:*` hints in your client requests. The unified API key works across all profiles, so you do not need separate authentication credentials for each configuration.