> For the complete documentation index, see [llms.txt](https://docs.cortecs.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cortecs.ai/integration-examples/tooling/litellm.md). Agents can also search and read this documentation through its [MCP server](https://docs.cortecs.ai/~gitbook/mcp).

# LiteLLM

Use Cortecs with the LiteLLM Python SDK and proxy

[LiteLLM](https://docs.litellm.ai/) provides a Python SDK and an OpenAI-compatible proxy for calling multiple LLM providers. Its native Cortecs integration lets you use Cortecs models through the same interface as your other providers.

{% hint style="info" %}
Create a Cortecs API key by following the [Member quickstart](https://docs.cortecs.ai/member-quickstart.md), then choose a model with the required capabilities from the [Models API](https://docs.cortecs.ai/api/models.md).
{% endhint %}

{% hint style="warning" %}
LiteLLM can Cortecs' credit-based `usage.cost` values as US dollars, inflating reported spend and triggering budget limits prematurely. See the [LiteLLM issue](https://github.com/BerriAI/litellm/issues/35829).

As a workaround, send `x-cortecs-cost-unit: USD` to Cortecs through LiteLLM's `extra_headers`, as shown in the examples below. Cortecs then returns these response cost fields in USD.
{% endhint %}

## 1. Install LiteLLM

For the Python SDK:

```bash
pip install --upgrade litellm
```

Set your API key and a Cortecs model ID in your environment:

```bash
export CORTECS_API_KEY="your-cortecs-api-key"
export CORTECS_MODEL="gpt-6.1-sol"
```

Use the `cortecs/` prefix when passing a model to LiteLLM. For example, the Cortecs model ID `gpt-6.1-sol` becomes `cortecs/gpt-6.1-sol`. LiteLLM reads `CORTECS_API_KEY` automatically and uses `https://api.cortecs.ai/v1` as the default API base URL.

## 2. Connect to Cortecs

### Responses API

Use Responses for new agent workflows:

```python
import os

import litellm

response = litellm.responses(
    model=f"cortecs/{os.environ['CORTECS_MODEL']}",
    input="Explain model routing in two sentences.",
    extra_headers={"x-cortecs-cost-unit": "USD"},
)

print(response.output[0].content[0].text)
```

### Chat Completions

For workflows that expect Chat Completions:

```python
import os

import litellm

response = litellm.completion(
    model=f"cortecs/{os.environ['CORTECS_MODEL']}",
    messages=[{"role": "user", "content": "Explain model routing in two sentences."}],
    extra_body={"preference": "balanced"},
    extra_headers={"x-cortecs-cost-unit": "USD"},
)

print(response.choices[0].message.content)
```

Pass Cortecs routing options such as `preference`, `allowed_providers` or `eu_native` through `extra_body`. See [Routing Concept](https://docs.cortecs.ai/routing/routing-concept.md) for the available options.

### Embeddings

Choose an embedding model from the Cortecs catalogue:

```python
import litellm

response = litellm.embedding(
    model="cortecs/qwen3-embedding-8b",
    input=["Explain semantic search."],
    extra_headers={"x-cortecs-cost-unit": "USD"},
)

print(response.data[0]["embedding"])
```

## 3. Use the LiteLLM proxy

The proxy lets existing applications call Cortecs through a shared LiteLLM endpoint.

Install the proxy dependencies:

```bash
pip install --upgrade 'litellm[proxy]'
```

Create a `config.yaml` file:

```yaml
model_list:
  - model_name: cortecs-chat
    litellm_params:
      model: cortecs/gpt-6.1-sol
      api_key: os.environ/CORTECS_API_KEY
      extra_headers:
        x-cortecs-cost-unit: USD
  - model_name: cortecs-decisions
    litellm_params:
      model: cortecs/clef-flash
      api_key: os.environ/CORTECS_API_KEY
      extra_headers:
        x-cortecs-cost-unit: USD

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
```

Set a proxy key and start the server from the same shell where you exported `CORTECS_API_KEY`:

```bash
export LITELLM_MASTER_KEY="sk-your-proxy-key"
litellm --config config.yaml
```

Send a request to the proxy:

```bash
curl http://localhost:4000/v1/responses \
  -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "cortecs-chat",
    "input": "Explain model routing in two sentences."
  }'
```

Applications use the `model_name` alias, such as `cortecs-chat`. The `litellm_params.model` value selects the Cortecs model. Authenticate applications with the LiteLLM proxy key; the proxy uses your Cortecs API key for upstream requests.

### Decisions

With the `cortecs-decisions` deployment above, call LiteLLM's decision endpoint:

```bash
curl http://localhost:4000/v1/decisions \
  -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "cortecs-decisions",
    "input": "My order arrived broken.",
    "questions": [
      {
        "type": "predicate",
        "name": "is_complaint",
        "instructions": "Is this a complaint?"
      }
    ]
  }'
```

LiteLLM translates this request to the Cortecs `/v1/systemone` format and returns a normalized decision response. See [Decisions](https://docs.cortecs.ai/api/decisions.md) for the Cortecs API reference.
