# Frameworks & SDKs

Radium inside the frameworks your application already runs on. Raw SDKs, agent frameworks, retrieval, and where to deploy it.

# Use AG2 with Radium

AG2 1.x, the current successor to AutoGen, supports OpenAI-compatible endpoints through `OpenAIConfig`. This guide uses the current async `ag2.Agent` API.

### Before you start

You need Python 3.10 or newer, a Radium API key, and a terminal or PowerShell window.

### 1. Create a project and install AG2

macOS or Linux:

```bash
mkdir radium-ag2
cd radium-ag2
python3 -m venv .venv
source .venv/bin/activate
python -m pip install "ag2[openai]"
```

Windows PowerShell:

```powershell
mkdir radium-ag2
cd radium-ag2
py -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install "ag2[openai]"
```

### 2. Set your Radium credentials

macOS or Linux:

```bash
export RADIUM_API_KEY="your-radium-api-key"
export RADIUM_MODEL="hal-1.0"
```

Windows PowerShell:

```powershell
$env:RADIUM_API_KEY = "your-radium-api-key"
$env:RADIUM_MODEL = "hal-1.0"
```

### 3. Create `main.py`

```python
import asyncio
import os

from ag2 import Agent
from ag2.config import OpenAIConfig


api_key = os.getenv("RADIUM_API_KEY")
if not api_key:
    raise SystemExit("Set RADIUM_API_KEY before running this program.")


async def main() -> None:
    assistant = Agent(
        "radium_assistant",
        prompt="Follow the user's instruction exactly.",
        config=OpenAIConfig(
            model=os.getenv("RADIUM_MODEL", "hal-1.0"),
            api_key=api_key,
            base_url="https://api.radium.cloud/v1",
            max_tokens=512,
            temperature=0,
            timeout=90,
        ),
    )
    reply = await assistant.ask("Reply with exactly: Radium connected.")
    if not reply.body or not reply.body.strip():
        raise RuntimeError("Radium returned no visible text.")
    print(f"RADIUM_RESPONSE: {reply.body.strip()}")


asyncio.run(main())
```

This connection example does not enable code-execution tools.

### 4. Run it

```bash
python main.py
```

Expected output:

```text
RADIUM_RESPONSE: Radium connected.
```

### Choose a model

```bash
export RADIUM_MODEL="tycho-1.0"  # or hal-1.0 or clarke-1.0
python main.py
```

### Migrate an existing AG2 agent

Create a Radium configuration and pass it to the agent:

```python
config = OpenAIConfig(
    model="hal-1.0",
    api_key=os.environ["RADIUM_API_KEY"],
    base_url="https://api.radium.cloud/v1",
    max_tokens=512,
)
agent = Agent("radium_assistant", config=config)
```

AG2 1.x removed the legacy `autogen.AssistantAgent` interface. If an older project imports `autogen`, it uses AG2 Classic and needs either the classic configuration format or a migration to the current API shown here.

### Troubleshooting

- `ImportError` for `autogen`: follow the current `ag2.Agent` imports shown above.
- Authentication errors: set the Radium key in the active terminal.
- `404`: check the base URL and model ID.
- Code execution concerns: do not add execution tools until they have been reviewed and sandboxed.

### Validation

Version note: these instructions were verified with Python 3.12.7 and `ag2[openai]==1.0.2` on August 20, 2026. You do not need that exact package version. Text generation and callable-tool execution passed with `hal-1.0`, `clarke-1.0`, and `tycho-1.0`.

Reference: [AG2 model configuration](https://docs.ag2.ai/docs/user-guide/model_configuration/).

### Next

- [API quickstart](/books/radium-api/page/api-quickstart), for calling Radium directly
- [Tool calling](/books/radium-api/page/tool-calling-and-mcp), for the `tool_use` and `tool_result` contract

# Use Agno with Radium

Agno's `OpenAILike` model is designed for OpenAI-compatible APIs. Configure it with Radium's endpoint and use it with normal Agno agents.

### Before you start

You need Python 3.10 or newer, a Radium API key, and a terminal or PowerShell window.

### 1. Create a project and install Agno

macOS or Linux:

```bash
mkdir radium-agno
cd radium-agno
python3 -m venv .venv
source .venv/bin/activate
python -m pip install agno openai
```

Windows PowerShell:

```powershell
mkdir radium-agno
cd radium-agno
py -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install agno openai
```

### 2. Set your Radium credentials

macOS or Linux:

```bash
export RADIUM_API_KEY="your-radium-api-key"
export RADIUM_MODEL="hal-1.0"
```

Windows PowerShell:

```powershell
$env:RADIUM_API_KEY = "your-radium-api-key"
$env:RADIUM_MODEL = "hal-1.0"
```

### 3. Create `main.py`

```python
import os

from agno.agent import Agent
from agno.models.openai.like import OpenAILike


api_key = os.getenv("RADIUM_API_KEY")
if not api_key:
    raise SystemExit("Set RADIUM_API_KEY before running this program.")

agent = Agent(
    model=OpenAILike(
        id=os.getenv("RADIUM_MODEL", "hal-1.0"),
        api_key=api_key,
        base_url="https://api.radium.cloud/v1",
        max_tokens=512,
        temperature=0,
        timeout=90,
    ),
    instructions="Follow the user's instruction exactly.",
)

result = agent.run("Reply with exactly: Radium connected.", stream=False)
if not result.content or not str(result.content).strip():
    raise RuntimeError("Radium returned no visible text.")
print(f"RADIUM_RESPONSE: {str(result.content).strip()}")
```

### 4. Run it

```bash
python main.py
```

Expected output:

```text
RADIUM_RESPONSE: Radium connected.
```

### Choose a model

```bash
export RADIUM_MODEL="clarke-1.0"  # or hal-1.0 or tycho-1.0
python main.py
```

### Migrate an existing Agno agent

Replace its current model:

```python
model = OpenAILike(
    id="hal-1.0",
    api_key=os.environ["RADIUM_API_KEY"],
    base_url="https://api.radium.cloud/v1",
    max_tokens=512,
)
agent = Agent(model=model)
```

Your agent instructions, knowledge sources, storage, and tools can remain unchanged. External tools keep their own dependencies and credentials.

### Troubleshooting

- Authentication errors: verify the key in the active terminal.
- `404`: check the endpoint and exact model ID.
- Import errors: install both pinned packages inside the active virtual environment.
- Tool errors: validate each tool's own credentials separately from the Radium connection.

### Validation

Version note: these instructions were verified with Python 3.12.7, `agno==2.9.0`, and `openai==2.54.0` on August 20, 2026. You do not need those exact package versions. Text generation and callable-tool execution passed with `hal-1.0`, `clarke-1.0`, and `tycho-1.0`.

Reference: [Agno OpenAI-compatible models](https://docs.agno.com/models/providers/openai-like).

### Next

- [API quickstart](/books/radium-api/page/api-quickstart), for calling Radium directly
- [Tool calling](/books/radium-api/page/tool-calling-and-mcp), for the `tool_use` and `tool_result` contract

# Use CrewAI with Radium

CrewAI's `LLM` class uses LiteLLM for model connections. Select the OpenAI-compatible protocol with an `openai/` prefix and send requests to Radium.

### Before you start

You need Python 3.10 or newer, a Radium API key, and a terminal or PowerShell window.

### 1. Create a project and install CrewAI

macOS or Linux:

```bash
mkdir radium-crewai
cd radium-crewai
python3 -m venv .venv
source .venv/bin/activate
python -m pip install crewai
```

Windows PowerShell:

```powershell
mkdir radium-crewai
cd radium-crewai
py -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install crewai
```

### 2. Set your Radium credentials

macOS or Linux:

```bash
export RADIUM_API_KEY="your-radium-api-key"
export RADIUM_MODEL="hal-1.0"
export CREWAI_TRACING_ENABLED="false"
```

Windows PowerShell:

```powershell
$env:RADIUM_API_KEY = "your-radium-api-key"
$env:RADIUM_MODEL = "hal-1.0"
$env:CREWAI_TRACING_ENABLED = "false"
```

Tracing is disabled here so this connection example does not ask for an additional tracing setup.

### 3. Create `main.py`

```python
import os

from crewai import Agent, Crew, LLM, Task


api_key = os.getenv("RADIUM_API_KEY")
if not api_key:
    raise SystemExit("Set RADIUM_API_KEY before running this program.")

model = os.getenv("RADIUM_MODEL", "hal-1.0")
llm = LLM(
    model=f"openai/{model}",
    api_key=api_key,
    base_url="https://api.radium.cloud/v1",
    max_tokens=512,
    temperature=0,
    timeout=90,
)

assistant = Agent(
    role="Radium connection tester",
    goal="Follow the user's instruction exactly",
    backstory="You provide short, exact responses.",
    llm=llm,
    allow_delegation=False,
    verbose=False,
)
task = Task(
    description="Reply with exactly: Radium connected.",
    expected_output="The exact text 'Radium connected.' and nothing else.",
    agent=assistant,
)

result = Crew(agents=[assistant], tasks=[task], verbose=False).kickoff()
if not result.raw or not result.raw.strip():
    raise RuntimeError("Radium returned no visible text.")
print(f"RADIUM_RESPONSE: {result.raw.strip()}")
```

The `openai/` prefix is required for LiteLLM provider routing. Radium still receives the model ID without that prefix.

### 4. Run it

```bash
python main.py
```

Expected final output:

```text
RADIUM_RESPONSE: Radium connected.
```

CrewAI may print status messages before the final line.

### Choose a model

```bash
export RADIUM_MODEL="tycho-1.0"  # or hal-1.0 or clarke-1.0
python main.py
```

### Migrate an existing crew

Create one Radium-backed LLM and pass it to every agent that should use Radium:

```python
llm = LLM(
    model="openai/hal-1.0",
    api_key=os.environ["RADIUM_API_KEY"],
    base_url="https://api.radium.cloud/v1",
    max_tokens=512,
)

agent = Agent(..., llm=llm)
```

Your roles, goals, tasks, and crew process can remain unchanged. Planning, memory, and external tools may require additional model calls or credentials.

### Troubleshooting

- Authentication errors: set the API key in the same terminal running CrewAI.
- Provider errors: keep the `openai/` prefix on the model passed to `LLM`.
- `404`: use the exact base URL and model IDs shown above.
- Unexpected tracing prompts: set `CREWAI_TRACING_ENABLED=false`.

### Validation

Version note: these instructions were verified with Python 3.12.7 and `crewai==1.15.17` on August 20, 2026. You do not need that exact package version. Agent/task generation and CrewAI tool execution passed with `hal-1.0`, `clarke-1.0`, and `tycho-1.0`.

Reference: [CrewAI custom LLM guide](https://docs.crewai.com/en/learn/llm-connections).

### Next

- [API quickstart](/books/radium-api/page/api-quickstart), for calling Radium directly
- [Tool calling](/books/radium-api/page/tool-calling-and-mcp), for the `tool_use` and `tool_result` contract

# Use DSPy with Radium

DSPy connects to OpenAI-compatible APIs through LiteLLM. Prefix the Radium model with `openai/`, then provide Radium's API key and base URL.

### Before you start

You need Python 3.10 or newer, a Radium API key, and a terminal or PowerShell window.

### 1. Create a project and install DSPy

macOS or Linux:

```bash
mkdir radium-dspy
cd radium-dspy
python3 -m venv .venv
source .venv/bin/activate
python -m pip install dspy
```

Windows PowerShell:

```powershell
mkdir radium-dspy
cd radium-dspy
py -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install dspy
```

### 2. Set your Radium credentials

macOS or Linux:

```bash
export RADIUM_API_KEY="your-radium-api-key"
export RADIUM_MODEL="hal-1.0"
```

Windows PowerShell:

```powershell
$env:RADIUM_API_KEY = "your-radium-api-key"
$env:RADIUM_MODEL = "hal-1.0"
```

### 3. Create `main.py`

```python
import os

import dspy


api_key = os.getenv("RADIUM_API_KEY")
if not api_key:
    raise SystemExit("Set RADIUM_API_KEY before running this program.")

model = os.getenv("RADIUM_MODEL", "hal-1.0")
lm = dspy.LM(
    f"openai/{model}",
    api_key=api_key,
    api_base="https://api.radium.cloud/v1",
    max_tokens=512,
    temperature=0,
    timeout=90,
)
dspy.configure(lm=lm)

responses = lm(
    messages=[
        {"role": "system", "content": "Follow the user's instruction exactly."},
        {"role": "user", "content": "Reply with exactly: Radium connected."},
    ]
)
raw = responses[0] if responses else None
content = raw.get("text") if isinstance(raw, dict) else raw

if not content or not str(content).strip():
    raise RuntimeError("Radium returned no visible text.")
print(f"RADIUM_RESPONSE: {str(content).strip()}")
```

DSPy may return a string or a dictionary containing `text` and `reasoning_content`. The code handles both response shapes.

### 4. Run it

```bash
python main.py
```

Expected output:

```text
RADIUM_RESPONSE: Radium connected.
```

### Choose a model

```bash
export RADIUM_MODEL="clarke-1.0"  # or hal-1.0 or tycho-1.0
python main.py
```

### Migrate an existing DSPy program

Configure the global language model, then keep using your existing signatures and modules:

```python
lm = dspy.LM(
    "openai/hal-1.0",
    api_key=os.environ["RADIUM_API_KEY"],
    api_base="https://api.radium.cloud/v1",
    max_tokens=512,
)
dspy.configure(lm=lm)
```

DSPy optimizers can make many model calls. Test latency and usage on a small dataset before starting a large optimization.

### Tool-calling note

> **Known issue with hal-1.0**
> DSPy `ReAct` executed tools and returned grounded answers with all three models. With `hal-1.0`, DSPy logged an output-truncation warning during the agent trace at both 512 and 1024 output tokens, though the tool still ran once and the final answer was correct. Test longer ReAct workflows before relying on them in production.

### Troubleshooting

- Authentication errors: verify the key in the active terminal.
- Provider errors: include `openai/` before the model ID passed to `dspy.LM`.
- Empty output: retain the response-shape normalization shown above.
- Large optimizer jobs: reduce the dataset first to confirm expected request volume.

### Validation

Version note: these instructions were verified with Python 3.12.7 and `dspy==3.3.0` on August 20, 2026. You do not need that exact package version. Text generation passed with `hal-1.0`, `clarke-1.0`, and `tycho-1.0`; ReAct tool calling passed with the caveat above.

Reference: [DSPy language model documentation](https://dspy.ai/learn/programming/language_models/).

### Next

- [API quickstart](/books/radium-api/page/api-quickstart), for calling Radium directly
- [Tool calling](/books/radium-api/page/tool-calling-and-mcp), for the `tool_use` and `tool_result` contract

# Use LangChain with Radium

LangChain's `ChatOpenAI` class works with OpenAI-compatible APIs. Point it at Radium and continue using normal LangChain messages, chains, and agents.

### Before you start

You need Python 3.10 or newer, a Radium API key, and a terminal or PowerShell window.

### 1. Create a project and install LangChain

macOS or Linux:

```bash
mkdir radium-langchain
cd radium-langchain
python3 -m venv .venv
source .venv/bin/activate
python -m pip install langchain-openai
```

Windows PowerShell:

```powershell
mkdir radium-langchain
cd radium-langchain
py -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install langchain-openai
```

### 2. Set your Radium credentials

macOS or Linux:

```bash
export RADIUM_API_KEY="your-radium-api-key"
export RADIUM_MODEL="hal-1.0"
```

Windows PowerShell:

```powershell
$env:RADIUM_API_KEY = "your-radium-api-key"
$env:RADIUM_MODEL = "hal-1.0"
```

### 3. Create `main.py`

```python
import os

from langchain_openai import ChatOpenAI


api_key = os.getenv("RADIUM_API_KEY")
if not api_key:
    raise SystemExit("Set RADIUM_API_KEY before running this program.")

llm = ChatOpenAI(
    model=os.getenv("RADIUM_MODEL", "hal-1.0"),
    api_key=api_key,
    base_url="https://api.radium.cloud/v1",
    max_tokens=512,
    temperature=0,
    timeout=90,
    max_retries=0,
)

response = llm.invoke(
    [
        ("system", "Follow the user's instruction exactly."),
        ("human", "Reply with exactly: Radium connected."),
    ]
)

if not response.content or not str(response.content).strip():
    raise RuntimeError("Radium returned no visible text.")
print(f"RADIUM_RESPONSE: {str(response.content).strip()}")
```

### 4. Run it

```bash
python main.py
```

Expected output:

```text
RADIUM_RESPONSE: Radium connected.
```

### Choose a model

Use any validated Radium model:

```bash
export RADIUM_MODEL="clarke-1.0"  # or hal-1.0 or tycho-1.0
python main.py
```

### Migrate an existing LangChain app

Replace the model initialization used by your chain or agent:

```python
llm = ChatOpenAI(
    model="hal-1.0",
    api_key=os.environ["RADIUM_API_KEY"],
    base_url="https://api.radium.cloud/v1",
    max_tokens=512,
)
```

Your prompts, chains, tools, and message objects can remain unchanged. This integration uses Chat Completions, so do not enable `use_responses_api`.

### Troubleshooting

- Authentication errors: set `RADIUM_API_KEY` in the terminal running the program.
- `404`: keep `/v1` in `base_url` and use an exact Radium model ID.
- Empty output: use `max_tokens=512` or higher.
- Import errors: reactivate `.venv` and reinstall the pinned package.

### Validation

Version note: these instructions were verified with Python 3.12.7 and `langchain-openai==1.6.0` on August 20, 2026. You do not need that exact package version. Text generation and bound-tool calling passed with `hal-1.0`, `clarke-1.0`, and `tycho-1.0`.

Reference: [LangChain ChatOpenAI documentation](https://docs.langchain.com/oss/python/integrations/chat/openai).

### Next

- [API quickstart](/books/radium-api/page/api-quickstart), for calling Radium directly
- [Tool calling](/books/radium-api/page/tool-calling-and-mcp), for the `tool_use` and `tool_result` contract

# Use LangGraph with Radium

LangGraph does not connect to a model provider by itself. Configure a Radium-backed `ChatOpenAI` model and call it from your graph nodes.

### Before you start

You need Python 3.10 or newer, a Radium API key, and a terminal or PowerShell window.

### 1. Create a project and install the packages

macOS or Linux:

```bash
mkdir radium-langgraph
cd radium-langgraph
python3 -m venv .venv
source .venv/bin/activate
python -m pip install langgraph langchain-openai
```

Windows PowerShell:

```powershell
mkdir radium-langgraph
cd radium-langgraph
py -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install langgraph langchain-openai
```

### 2. Set your Radium credentials

macOS or Linux:

```bash
export RADIUM_API_KEY="your-radium-api-key"
export RADIUM_MODEL="hal-1.0"
```

Windows PowerShell:

```powershell
$env:RADIUM_API_KEY = "your-radium-api-key"
$env:RADIUM_MODEL = "hal-1.0"
```

### 3. Create `main.py`

```python
import os

from langchain_openai import ChatOpenAI
from langgraph.graph import END, START, MessagesState, StateGraph


api_key = os.getenv("RADIUM_API_KEY")
if not api_key:
    raise SystemExit("Set RADIUM_API_KEY before running this program.")

llm = ChatOpenAI(
    model=os.getenv("RADIUM_MODEL", "hal-1.0"),
    api_key=api_key,
    base_url="https://api.radium.cloud/v1",
    max_tokens=512,
    temperature=0,
    timeout=90,
    max_retries=0,
)


def call_radium(state: MessagesState):
    return {"messages": [llm.invoke(state["messages"])]}


builder = StateGraph(MessagesState)
builder.add_node("call_radium", call_radium)
builder.add_edge(START, "call_radium")
builder.add_edge("call_radium", END)
graph = builder.compile()

result = graph.invoke(
    {
        "messages": [
            {"role": "system", "content": "Follow the user's instruction exactly."},
            {"role": "user", "content": "Reply with exactly: Radium connected."},
        ]
    }
)

content = result["messages"][-1].content
if not content or not str(content).strip():
    raise RuntimeError("Radium returned no visible text.")
print(f"RADIUM_RESPONSE: {str(content).strip()}")
```

### 4. Run it

```bash
python main.py
```

Expected output:

```text
RADIUM_RESPONSE: Radium connected.
```

### Choose a model

```bash
export RADIUM_MODEL="tycho-1.0"  # or hal-1.0 or clarke-1.0
python main.py
```

### Migrate an existing graph

Replace the model used inside your existing nodes:

```python
llm = ChatOpenAI(
    model="hal-1.0",
    api_key=os.environ["RADIUM_API_KEY"],
    base_url="https://api.radium.cloud/v1",
    max_tokens=512,
)
```

Your state schema, nodes, edges, routing, and checkpoints do not need to change.

### Troubleshooting

- Authentication errors: check the API key in the active terminal.
- `404`: use the exact base URL and one of the three listed model IDs.
- State errors: make sure the graph node returns a `messages` list.
- Import errors: activate `.venv` and rerun the installation command.

### Validation

Version note: these instructions were verified with Python 3.12.7, `langgraph==1.2.11`, and `langchain-openai==1.6.0` on August 20, 2026. You do not need those exact package versions. Text generation and an agent tool loop passed with `hal-1.0`, `clarke-1.0`, and `tycho-1.0`.

Reference: [LangGraph quick start](https://docs.langchain.com/oss/python/langgraph/quickstart).

### Next

- [API quickstart](/books/radium-api/page/api-quickstart), for calling Radium directly
- [Tool calling](/books/radium-api/page/tool-calling-and-mcp), for the `tool_use` and `tool_result` contract

# Use LlamaIndex with Radium

LlamaIndex provides `OpenAILike` for third-party OpenAI-compatible APIs. Use it to connect a LlamaIndex application to Radium.

### Before you start

You need Python 3.10 or newer, a Radium API key, and a terminal or PowerShell window.

### 1. Create a project and install LlamaIndex

macOS or Linux:

```bash
mkdir radium-llamaindex
cd radium-llamaindex
python3 -m venv .venv
source .venv/bin/activate
python -m pip install llama-index-llms-openai-like
```

Windows PowerShell:

```powershell
mkdir radium-llamaindex
cd radium-llamaindex
py -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install llama-index-llms-openai-like
```

### 2. Set your Radium credentials

macOS or Linux:

```bash
export RADIUM_API_KEY="your-radium-api-key"
export RADIUM_MODEL="hal-1.0"
```

Windows PowerShell:

```powershell
$env:RADIUM_API_KEY = "your-radium-api-key"
$env:RADIUM_MODEL = "hal-1.0"
```

### 3. Create `main.py`

```python
import os

from llama_index.core.llms import ChatMessage
from llama_index.llms.openai_like import OpenAILike


api_key = os.getenv("RADIUM_API_KEY")
if not api_key:
    raise SystemExit("Set RADIUM_API_KEY before running this program.")

llm = OpenAILike(
    model=os.getenv("RADIUM_MODEL", "hal-1.0"),
    api_key=api_key,
    api_base="https://api.radium.cloud/v1",
    is_chat_model=True,
    max_tokens=512,
    temperature=0,
    timeout=90,
)

response = llm.chat(
    [
        ChatMessage(role="system", content="Follow the user's instruction exactly."),
        ChatMessage(role="user", content="Reply with exactly: Radium connected."),
    ]
)

content = response.message.content
if not content or not content.strip():
    raise RuntimeError("Radium returned no visible text.")
print(f"RADIUM_RESPONSE: {content.strip()}")
```

LlamaIndex calls the endpoint setting `api_base`, not `base_url`.

### 4. Run it

```bash
python main.py
```

Expected output:

```text
RADIUM_RESPONSE: Radium connected.
```

### Choose a model

```bash
export RADIUM_MODEL="clarke-1.0"  # or hal-1.0 or tycho-1.0
python main.py
```

### Migrate an existing LlamaIndex app

Replace its current LLM object:

```python
llm = OpenAILike(
    model="hal-1.0",
    api_key=os.environ["RADIUM_API_KEY"],
    api_base="https://api.radium.cloud/v1",
    is_chat_model=True,
    max_tokens=512,
)
```

Pass `llm` to the existing index, query engine, workflow, or agent. A RAG application still needs a separate embedding model; do not use these chat model IDs as embedding model IDs.

### Troubleshooting

- Authentication errors: check `RADIUM_API_KEY` in the active terminal.
- `404`: keep `/v1` in `api_base` and use an exact Radium model ID.
- Empty output: use at least 512 output tokens.
- Import errors: activate `.venv` and reinstall the pinned package.

### Validation

Version note: these instructions were verified with Python 3.12.7 and `llama-index-llms-openai-like==0.7.2` on August 20, 2026. You do not need that exact package version. Text generation and `FunctionAgent` tool calling passed with `hal-1.0`, `clarke-1.0`, and `tycho-1.0`.

Reference: [LlamaIndex OpenAILike integration](https://docs.llamaindex.ai/en/stable/api_reference/llms/openai_like/).

### Next

- [API quickstart](/books/radium-api/page/api-quickstart), for calling Radium directly
- [Tool calling](/books/radium-api/page/tool-calling-and-mcp), for the `tool_use` and `tool_result` contract

# Use the OpenAI Python SDK with Radium

Radium exposes an OpenAI-compatible Chat Completions API. If your application already uses the OpenAI Python SDK, you only need to change the API key, base URL, and model name.

This guide creates a small program that sends one request and prints the response.

### Before you start

You need:

- Python 3.10 or newer
- A Radium API key
- A terminal or PowerShell window

### 1. Create a project and install the SDK

macOS or Linux:

```bash
mkdir radium-openai-python
cd radium-openai-python
python3 -m venv .venv
source .venv/bin/activate
python -m pip install openai
```

Windows PowerShell:

```powershell
mkdir radium-openai-python
cd radium-openai-python
py -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install openai
```

### 2. Set your Radium credentials

macOS or Linux:

```bash
export RADIUM_API_KEY="your-radium-api-key"
export RADIUM_MODEL="hal-1.0"
```

Windows PowerShell:

```powershell
$env:RADIUM_API_KEY = "your-radium-api-key"
$env:RADIUM_MODEL = "hal-1.0"
```

Keep the key on the server. Do not paste it into `main.py`, commit it, or expose it in browser code.

### 3. Create `main.py`

```python
import os

from openai import OpenAI


api_key = os.getenv("RADIUM_API_KEY")
if not api_key:
    raise SystemExit("Set RADIUM_API_KEY before running this program.")

model = os.getenv("RADIUM_MODEL", "hal-1.0")
client = OpenAI(
    api_key=api_key,
    base_url="https://api.radium.cloud/v1",
    timeout=90,
    max_retries=0,
)

response = client.chat.completions.create(
    model=model,
    messages=[
        {"role": "system", "content": "Follow the user's instruction exactly."},
        {"role": "user", "content": "Reply with exactly: Radium connected."},
    ],
    max_tokens=512,
    temperature=0,
)

content = response.choices[0].message.content
if not content or not content.strip():
    raise RuntimeError("Radium returned no visible text.")
print(f"RADIUM_RESPONSE: {content.strip()}")
```

The base URL must include `/v1`. Do not append `/chat/completions`; the SDK adds that path.

### 4. Run it

```bash
python main.py
```

Expected output:

```text
RADIUM_RESPONSE: Radium connected.
```

### Choose a model

Set `RADIUM_MODEL` to any validated model before running the program:

```bash
export RADIUM_MODEL="hal-1.0"
# or: clarke-1.0
# or: tycho-1.0
python main.py
```

### Migrate an existing OpenAI client

Before:

```python
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
```

After:

```python
client = OpenAI(
    api_key=os.environ["RADIUM_API_KEY"],
    base_url="https://api.radium.cloud/v1",
)
```

Keep your existing messages and response parsing. Replace the old model ID with `hal-1.0`, `clarke-1.0`, or `tycho-1.0`.

### Troubleshooting

- `401` or `403`: verify that `RADIUM_API_KEY` is set in the same terminal running Python.
- `404`: verify the base URL and use one of the model IDs listed above.
- Empty output: keep `max_tokens` at 512 or higher so model reasoning does not consume the visible response allowance.
- `ModuleNotFoundError`: activate `.venv` and rerun the installation command.

### Validation

Version note: these instructions were verified with Python 3.12.7 and `openai==2.54.0` on August 20, 2026. You do not need that exact package version. Text generation and a complete function-calling loop passed with `hal-1.0`, `clarke-1.0`, and `tycho-1.0`.

Reference: [OpenAI Python library](https://github.com/openai/openai-python).

### Next

- [API quickstart](/books/radium-api/page/api-quickstart), for calling Radium directly
- [Tool calling](/books/radium-api/page/tool-calling-and-mcp), for the `tool_use` and `tool_result` contract

# Use PydanticAI with Radium

PydanticAI supports custom OpenAI-compatible providers. Construct an `OpenAIChatModel` explicitly so requests use Radium's Chat Completions endpoint.

### Before you start

You need Python 3.10 or newer, a Radium API key, and a terminal or PowerShell window.

### 1. Create a project and install PydanticAI

macOS or Linux:

```bash
mkdir radium-pydanticai
cd radium-pydanticai
python3 -m venv .venv
source .venv/bin/activate
python -m pip install "pydantic-ai-slim[openai]"
```

Windows PowerShell:

```powershell
mkdir radium-pydanticai
cd radium-pydanticai
py -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install "pydantic-ai-slim[openai]"
```

### 2. Set your Radium credentials

macOS or Linux:

```bash
export RADIUM_API_KEY="your-radium-api-key"
export RADIUM_MODEL="hal-1.0"
```

Windows PowerShell:

```powershell
$env:RADIUM_API_KEY = "your-radium-api-key"
$env:RADIUM_MODEL = "hal-1.0"
```

### 3. Create `main.py`

```python
import os

from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.openai import OpenAIProvider


api_key = os.getenv("RADIUM_API_KEY")
if not api_key:
    raise SystemExit("Set RADIUM_API_KEY before running this program.")

model = OpenAIChatModel(
    os.getenv("RADIUM_MODEL", "hal-1.0"),
    provider=OpenAIProvider(
        api_key=api_key,
        base_url="https://api.radium.cloud/v1",
    ),
)
agent = Agent(
    model,
    system_prompt="Follow the user's instruction exactly.",
    model_settings={"max_tokens": 512, "temperature": 0},
)

result = agent.run_sync("Reply with exactly: Radium connected.")
if not result.output or not str(result.output).strip():
    raise RuntimeError("Radium returned no visible text.")
print(f"RADIUM_RESPONSE: {str(result.output).strip()}")
```

Do not use the shorthand `openai:hal-1.0`. Constructing `OpenAIChatModel` explicitly ensures PydanticAI uses the custom Radium provider and Chat Completions endpoint.

### 4. Run it

```bash
python main.py
```

Expected output:

```text
RADIUM_RESPONSE: Radium connected.
```

### Choose a model

```bash
export RADIUM_MODEL="tycho-1.0"  # or hal-1.0 or clarke-1.0
python main.py
```

### Migrate an existing PydanticAI agent

Replace its model/provider configuration:

```python
model = OpenAIChatModel(
    "hal-1.0",
    provider=OpenAIProvider(
        api_key=os.environ["RADIUM_API_KEY"],
        base_url="https://api.radium.cloud/v1",
    ),
)
agent = Agent(model)
```

Your system prompts, dependency types, tools, and output types can remain unchanged.

### Troubleshooting

- Authentication errors: set the key in the terminal running Python.
- Calls going to OpenAI instead of Radium: use the explicit `OpenAIProvider` construction shown above.
- `404`: verify `/v1` and the exact model name.
- Empty output: keep the output allowance at 512 or higher.

### Validation

Version note: these instructions were verified with Python 3.12.7 and `pydantic-ai-slim[openai]==2.31.1` on August 20, 2026. You do not need that exact package version. Text generation and `tool_plain` execution passed with `hal-1.0`, `clarke-1.0`, and `tycho-1.0`.

Reference: [PydanticAI OpenAI-compatible models](https://pydantic.dev/docs/ai/models/openai/#openai-compatible-models).

### Next

- [API quickstart](/books/radium-api/page/api-quickstart), for calling Radium directly
- [Tool calling](/books/radium-api/page/tool-calling-and-mcp), for the `tool_use` and `tool_result` contract

# Use the Vercel AI SDK with Radium

## Use the Vercel AI SDK with Radium

Use the AI SDK's OpenAI-compatible provider to call Radium from Node.js or server-side code in a Next.js application.

### Before you start

You need:

- Node.js 22 or newer
- npm
- A Radium API key

Radium calls must run on the server. Never expose the key through browser code or a `NEXT_PUBLIC_...` environment variable.

### 1. Create a project and install the packages

```bash
mkdir radium-vercel-ai-sdk
cd radium-vercel-ai-sdk
npm init -y
npm pkg set type=module
npm install ai @ai-sdk/openai-compatible
```

### 2. Set your Radium credentials

macOS or Linux:

```bash
export RADIUM_API_KEY="your-radium-api-key"
export RADIUM_MODEL="hal-1.0"
```

Windows PowerShell:

```powershell
$env:RADIUM_API_KEY = "your-radium-api-key"
$env:RADIUM_MODEL = "hal-1.0"
```

### 3. Create `main.mjs`

```javascript
import { generateText } from "ai";
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";

if (!process.env.RADIUM_API_KEY) {
  throw new Error("Set RADIUM_API_KEY before running this program.");
}

const radium = createOpenAICompatible({
  name: "radium",
  apiKey: process.env.RADIUM_API_KEY,
  baseURL: "https://api.radium.cloud/v1",
});

const { text } = await generateText({
  model: radium.chatModel(process.env.RADIUM_MODEL ?? "hal-1.0"),
  system: "Follow the user's instruction exactly.",
  prompt: "Reply with exactly: Radium connected.",
  maxOutputTokens: 512,
  temperature: 0,
});

if (!text?.trim()) {
  throw new Error("Radium returned no visible text.");
}
console.log(`RADIUM_RESPONSE: ${text.trim()}`);
```

The base URL must include `/v1`. The provider adds `/chat/completions` itself.

### 4. Run it

```bash
node main.mjs
```

Expected output:

```text
RADIUM_RESPONSE: Radium connected.
```

### Choose a model

```bash
export RADIUM_MODEL="clarke-1.0"  # or hal-1.0 or tycho-1.0
node main.mjs
```

### Migrate an existing AI SDK application

Create the provider once:

```javascript
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";

const radium = createOpenAICompatible({
  name: "radium",
  apiKey: process.env.RADIUM_API_KEY,
  baseURL: "https://api.radium.cloud/v1",
});
```

Then replace the model supplied to `generateText`, `streamText`, or your server route:

```javascript
const model = radium.chatModel("hal-1.0");
```

Your prompts and server-side AI SDK handlers can remain unchanged.

### Troubleshooting

- Node version errors: use Node.js 22 or newer for the pinned packages.
- Authentication errors: verify `RADIUM_API_KEY` in the server process.
- `404`: use the exact base URL and one of the listed model IDs.
- Browser key exposure: move the call into a server route or server action.
- Provider compatibility warning: update both `ai` and `@ai-sdk/openai-compatible` together so they use compatible current releases.

### Validation

Version note: these instructions were verified with Node.js 24.1.0, `ai@7.0.71`, and `@ai-sdk/openai-compatible@3.0.33` on August 20, 2026. You do not need those exact package versions. Text generation and multi-step tool calling passed cleanly with `hal-1.0`, `clarke-1.0`, and `tycho-1.0`.

Reference: [Vercel AI SDK OpenAI-compatible providers](https://ai-sdk.dev/providers/openai-compatible-providers).

### Next

- [API quickstart](/books/radium-api/page/api-quickstart), for calling Radium directly
- [Tool calling](/books/radium-api/page/tool-calling-and-mcp), for the `tool_use` and `tool_result` contract