Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions content/en-US/recipes/litellm-qoder-cloud-agents-en/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
schema_version: 1
slug: litellm-qoder-cloud-agents-en
title: "Integrate Qoder Cloud Agents with LiteLLM"
summary: "Use a lightweight compatibility gateway to connect existing LiteLLM, OpenAI SDK, and Agent API clients to Qoder Cloud Agents, choosing Session continuity or Chat Completions compatibility as the task requires."
type: recipe
category: enterprise-integration
tags:
- agent
- api
- sdk
- session
- authentication
author:
name: 安辰
github: hellomypastor
locale: en-US
translation_of: litellm-qoder-cloud-agents
---

> Translated from the original Chinese recipe by 安辰 (hellomypastor). This English version is an AI-assisted translation.

## Goal and use case

Qoder Cloud Agents uses Agents, Environments, Sessions, and event streams to orchestrate long-running coding tasks. Many applications already have a model-call layer built around LiteLLM, the OpenAI Python SDK, or the Chat Completions API. This recipe uses a lightweight compatibility gateway to connect the two interfaces, so existing clients do not need to implement Session creation, message sending, or SSE event consumption themselves.

The gateway provides two integration paths:

| Scenario | Recommended interface | Why |
| --- | --- | --- |
| Existing LiteLLM or OpenAI SDK client | Model API | Preserve familiar Chat Completions request patterns |
| One-off requests that need a standard model response | Model API | Return an OpenAI-compatible response |
| Long-running coding tasks | Agent API | Preserve Agent and Session semantics |
| Continue a previous task | Agent API | Use `previous_interaction_id` to continue the original Session |
| Display execution results in real time | Agent API | Consume the SSE event stream directly |

Each Model API request currently creates a new Qoder Session. Use the Agent API when you need multiple turns to reuse the same working directory and task context.

## Steps

First, prepare an Agent, an Environment, and a PAT for local validation in Qoder Cloud Agents. Then go to the Demo directory and copy the example configuration:

```bash
cd demos/litellm-qoder-cloud-agents
cp .env.example .env
```

In `.env`, set `QODER_PAT`, `QODER_AGENT_ID`, and `QODER_ENVIRONMENT_ID`, and generate separate high-entropy random values for `GATEWAY_API_KEY` and `LITELLM_MASTER_KEY`. Do not commit `.env` to version control.

Start the Qoder-compatible gateway and LiteLLM with Docker Compose:

```bash
docker compose up --build
```

By default, the Agent API listens on port `4001` of the gateway service at `/v1/interactions`. The first request creates a Qoder Session. The `id` in the response is an opaque continuation identifier; pass it unchanged as `previous_interaction_id` in the next request to continue the original Session. Adding `"stream": true` to the request body switches the response to an SSE event stream.

LiteLLM listens on port `4000` of the model service by default, at `/v1/chat/completions`. The Demo's `config/litellm.yaml` registers the `qoder-cloud-agent` model and forwards requests to the gateway through an OpenAI-compatible provider. Existing OpenAI SDK clients only need to change `base_url`, the API key, and the model name.

## Verification

First, check the gateway's health:

```bash
curl "$QODER_GATEWAY_URL/health/liveliness"
```

Expect `{"status":"ok"}`. Then call the Agent API and the LiteLLM Model API separately: the Agent API should return an `id` beginning with `qca1.` and text output; the LiteLLM Model API should return `object: "chat.completion"` and non-empty `choices[0].message.content`.

The Demo also includes unit tests that do not access the external network. Using a mock Runner, they verify API authentication, Session continuation, streaming responses, and source attribution markers for new Sessions. See the Demo README for the full configuration, invocation commands, cleanup steps, and production safety boundaries.

[View the Demo source](https://github.com/QoderAI/cloud-agents-cookbook/tree/main/demos/litellm-qoder-cloud-agents)

## FAQ and production boundaries

If LiteLLM cannot find `qoder-cloud-agent`, confirm that the container has loaded the Demo's `config/litellm.yaml` and that `QODER_GATEWAY_BASE_URL` points to the gateway service from within the container network. If a request returns 401, check `GATEWAY_API_KEY` and `LITELLM_MASTER_KEY` separately: the former is used when calling the gateway, and the latter when calling LiteLLM. They serve different purposes.

This example is a compatibility layer for one Agent and one Environment, not a production-ready multi-tenant gateway. At a minimum, production deployments need TLS, network access controls, rate limiting, auditing, centralized secret management, and credential rotation. Real requests create or continue Qoder Sessions and consume credits; an Agent may also read or modify data and code accessible from the Environment. Use an isolated Environment and review the output.