> ## Documentation Index
> Fetch the complete documentation index at: https://docs.routor.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Code Assistant

> How to configure Routor for a coding assistant that handles everything from autocomplete to full refactors.

A coding assistant spans the full complexity range - from single-line autocomplete suggestions to multi-file refactors, architecture questions, and debugging complex logic. Unlike a chatbot, the quality floor matters more: a wrong code suggestion costs developer time.

**Savings on this workload: typically 30–45% vs Claude Sonnet 4.6 baseline.**

Savings are lower than a chatbot because code tasks skew toward STANDARD and COMPLEX tiers - but the savings on the 40–50% of requests that route below STANDARD are still substantial.

***

## Recommended Profile Settings

| Setting      | Value          | Reason                                                                    |
| ------------ | -------------- | ------------------------------------------------------------------------- |
| Tier floor   | STANDARD       | Never use NANO/SIMPLE/LIGHT for code - quality matters                    |
| Tier ceiling | COMPLEX        | Allow Claude Opus, DeepSeek V4 Pro, or GPT-5.5 for hard algorithmic tasks |
| Cost cap     | \$0.05/request | Code prompts can be long; \$0.05 is generous but bounded                  |
| Vision       | Optional       | Enable if users can paste screenshots of code/errors                      |
| Tool calling | On             | Enable if the assistant calls functions (file read, terminal, etc.)       |
| Tool quality | 70%+           | Require reliable tool use - code assistants often call tools              |

***

## Step 1 - Create the profile

1. Go to **Playground → Configure**
2. Name it `Code Assistant`
3. Set tier floor: **STANDARD**, ceiling: **COMPLEX**
4. Set cost cap: `$0.05`
5. Enable **Tool calling** if your assistant uses tools
6. If tool calling is on, set tool quality to **70%** minimum
7. Click **Save & get API key**

***

## Step 2 - Use the profile key in your app

### Node.js - with tool calling

```typescript theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  apiKey:  "sk-routor-YOUR_PROFILE_KEY",
  baseURL: "https://api.routor.io/v1",
});

const tools: OpenAI.Chat.ChatCompletionTool[] = [
  {
    type: "function",
    function: {
      name:        "read_file",
      description: "Read the contents of a file",
      parameters: {
        type:       "object",
        properties: { path: { type: "string" } },
        required:   ["path"],
      },
    },
  },
];

const response = await client.chat.completions.create({
  model:    "auto",
  messages: [
    { role: "system", content: "You are an expert software engineer." },
    { role: "user",   content: "Refactor the auth module in src/auth.ts to use async/await instead of callbacks." },
  ],
  tools,
  tool_choice: "auto",
});

// Routor picks STANDARD or higher - never routes code tasks to NANO/SIMPLE
console.log(response.choices[0].message);
```

### Python

```python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="sk-routor-YOUR_PROFILE_KEY",
    base_url="https://api.routor.io/v1",
)

def ask_code(prompt: str, context: str = "") -> str:
    messages = [
        {"role": "system", "content": "You are an expert software engineer."},
    ]
    if context:
        messages.append({"role": "user", "content": f"Context:\n{context}"})
    messages.append({"role": "user", "content": prompt})

    response = client.chat.completions.create(
        model="auto",
        messages=messages,
    )
    return response.choices[0].message.content

# Simple task → routes to STANDARD (Claude Sonnet 4.6 / GPT-5.4)
result = ask_code("What does this function do?", context="def foo(x): return x * 2")

# Complex task → routes to COMPLEX (Claude Sonnet, or DeepSeek Reasoner for proofs/derivations)
result = ask_code("Rewrite this entire authentication module to use JWT with refresh token rotation", context=open("auth.py").read())
```

***

## How routing looks for code tasks

| Task                                             | Expected tier | Typical model     |
| ------------------------------------------------ | ------------- | ----------------- |
| "What does `x?.foo` mean in TypeScript?"         | STANDARD      | Claude Haiku 4.5  |
| "Write a regex to match email addresses"         | STANDARD      | GPT-5.4           |
| "Refactor this 200-line auth module"             | COMPLEX       | Claude Sonnet 4.6 |
| "Implement a lock-free concurrent queue in Rust" | COMPLEX       | Claude Sonnet 4.6 |
| "Prove this sorting algorithm is O(n log n)"     | COMPLEX       | DeepSeek Reasoner |
| "Design a distributed rate limiter"              | COMPLEX       | Claude Sonnet 4.6 |

***

## Streaming for autocomplete

If you're building an IDE extension or real-time autocomplete, enable streaming:

```typescript theme={null}
const stream = await client.chat.completions.create({
  model:    "auto",
  messages: [{ role: "user", content: "Complete this function: function binarySearch(arr, target) {" }],
  stream:   true,
  max_tokens: 200,
});

let result = "";
for await (const chunk of stream) {
  const delta = chunk.choices[0]?.delta?.content ?? "";
  result += delta;
  process.stdout.write(delta); // stream to user
}
```

***

## Cost estimate

On a coding assistant handling 2,000 requests/day:

| Scenario                               | Daily cost    |
| -------------------------------------- | ------------- |
| All requests to Claude Sonnet 4.6      | \~\$60        |
| With Routor (STANDARD→COMPLEX profile) | \~\$35–42     |
| Savings                                | \~\$18–25/day |

Savings are lower than a chatbot because code tasks are genuinely harder and route to higher tiers. But the STANDARD floor means quality never drops below a capable model.

***

## Related

* [Create a routing profile](../playground/create-profile)
* [Understanding routing tiers](../tiers)
* [Cline / Roo Code integration](../guides/cline) - if you're using AI coding assistants
* [LangChain integration](../guides/langchain) - if you're using agents with tool calling
