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

# Usage with Common Model Providers and Frameworks

These examples show the recommended pattern for pairing a model provider with a Runloop Devbox:

1. Generate code with your model provider.
2. Write that code into a Devbox.
3. Execute it with the current Runloop SDKs.

## Shared Setup

### Initialization

```python Python theme={null}
from runloop_api_client import AsyncRunloopSDK

runloop = AsyncRunloopSDK()  # Uses RUNLOOP_API_KEY
```

```typescript TypeScript theme={null}
import { RunloopSDK } from '@runloop/api-client';

const runloop = new RunloopSDK(); // Uses RUNLOOP_API_KEY
```

### Prompt Definition

```python Python theme={null}
prompt = "\n".join([
    "Write a Python script that generates a maze.",
    "Requirements:",
    "1. Accept a --size argument using argparse.",
    "2. Generate a solvable maze.",
    "3. Print the maze using '#' for walls and spaces for paths.",
    "4. Mark the start with 'S' and the end with 'E'.",
    "Return only runnable Python code.",
])
```

```typescript TypeScript theme={null}
const prompt = [
  'Write a Python script that generates a maze.',
  'Requirements:',
  '1. Accept a --size argument using argparse.',
  '2. Generate a solvable maze.',
  "3. Print the maze using '#' for walls and spaces for paths.",
  "4. Mark the start with 'S' and the end with 'E'.",
  'Return only runnable Python code.',
].join('\n');
```

### Running Generated Code on a Devbox

```python Python theme={null}
async def run_generated_maze(runloop: AsyncRunloopSDK, maze_generation_script: str) -> None:
    devbox = await runloop.devbox.create()
    print("Devbox ID:", devbox.id)

    await devbox.file.write(
        file_path="gen_maze.py",
        contents=maze_generation_script,
    )

    result = await devbox.cmd.exec("python gen_maze.py --size 10")
    if result.exit_code == 0:
        print("Maze generated successfully\n", await result.stdout())
    else:
        print("Maze generation failed\n", await result.stderr())

    await devbox.shutdown()
```

```typescript TypeScript theme={null}
async function runGeneratedMaze(runloop: RunloopSDK, mazeGenerationScript: string) {
  const devbox = await runloop.devbox.create();
  console.log(`Devbox ID: ${devbox.id}`);

  await devbox.file.write({
    file_path: 'gen_maze.py',
    contents: mazeGenerationScript,
  });

  const result = await devbox.cmd.exec('python gen_maze.py --size 10');
  if (result.exitCode === 0) {
    console.log('Maze generated successfully\n', await result.stdout());
  } else {
    console.error('Maze generation failed\n', await result.stderr());
  }

  await devbox.shutdown();
}
```

> [!NOTE]
>
> The provider-specific examples below assume the shared `prompt` and helper function from the sections above.

## TypeScript Integrations

```typescript Claude theme={null}
import Anthropic from '@anthropic-ai/sdk';
import { RunloopSDK } from '@runloop/api-client';

const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
const runloop = new RunloopSDK();

async function generateMazeCreator() {
  const response = await anthropic.messages.create({
    model: 'claude-3-5-sonnet-20241022',
    max_tokens: 1000,
    system: 'Respond only with code. Do not include markdown fences.',
    messages: [{ role: 'user', content: prompt }],
  });

  const mazeGenerationScript = response.content[0]?.type === 'text' ? response.content[0].text : '';
  await runGeneratedMaze(runloop, mazeGenerationScript);
}

generateMazeCreator();
```

```typescript Gemini theme={null}
import { GoogleGenerativeAI } from '@google/generative-ai';
import { RunloopSDK } from '@runloop/api-client';

const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY!);
const model = genAI.getGenerativeModel({ model: process.env.GEMINI_MODEL ?? 'gemini-1.5-flash' });
const runloop = new RunloopSDK();

async function generateMazeCreator() {
  const response = await model.generateContent(prompt);
  const mazeGenerationScript = response.response.text();
  await runGeneratedMaze(runloop, mazeGenerationScript);
}

generateMazeCreator();
```

```typescript OpenAI theme={null}
import OpenAI from 'openai';
import { RunloopSDK } from '@runloop/api-client';

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const runloop = new RunloopSDK();

async function generateMazeCreator() {
  const response = await openai.chat.completions.create({
    model: 'gpt-4o-mini',
    temperature: 0,
    messages: [{ role: 'user', content: prompt }],
  });

  const mazeGenerationScript = response.choices[0]?.message?.content ?? '';
  await runGeneratedMaze(runloop, mazeGenerationScript);
}

generateMazeCreator();
```

```typescript LangChain theme={null}
import { ChatOpenAI } from '@langchain/openai';
import { ChatPromptTemplate } from '@langchain/core/prompts';
import { StringOutputParser } from '@langchain/core/output_parsers';
import { RunloopSDK } from '@runloop/api-client';

const runloop = new RunloopSDK();

async function generateMazeCreator() {
  const llm = new ChatOpenAI({ model: 'gpt-4o-mini', temperature: 0 });
  const promptTemplate = ChatPromptTemplate.fromMessages([
    ['system', 'Respond only with runnable Python code.'],
    ['human', '{input}'],
  ]);

  const chain = promptTemplate.pipe(llm).pipe(new StringOutputParser());
  const mazeGenerationScript = await chain.invoke({ input: prompt });
  await runGeneratedMaze(runloop, mazeGenerationScript);
}

generateMazeCreator();
```

```typescript VercelAI theme={null}
import { openai } from '@ai-sdk/openai';
import { generateText } from 'ai';
import { RunloopSDK } from '@runloop/api-client';

const runloop = new RunloopSDK();

async function generateMazeCreator() {
  const { text: mazeGenerationScript } = await generateText({
    model: openai('gpt-4o-mini'),
    prompt,
  });

  await runGeneratedMaze(runloop, mazeGenerationScript);
}

generateMazeCreator();
```

## Python Integrations

```python Claude theme={null}
import asyncio
import os
from anthropic import AsyncAnthropic
from runloop_api_client import AsyncRunloopSDK

anthropic = AsyncAnthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
runloop = AsyncRunloopSDK()

async def generate_maze_creator() -> None:
    response = await anthropic.messages.create(
        model="claude-3-5-sonnet-20241022",
        max_tokens=1000,
        system="Respond only with runnable Python code.",
        messages=[{"role": "user", "content": prompt}],
    )
    maze_generation_script = response.content[0].text
    await run_generated_maze(runloop, maze_generation_script)

asyncio.run(generate_maze_creator())
```

```python Gemini theme={null}
import asyncio
import os
import google.generativeai as genai
from runloop_api_client import AsyncRunloopSDK

genai.configure(api_key=os.environ["GEMINI_API_KEY"])
runloop = AsyncRunloopSDK()
model = genai.GenerativeModel("gemini-1.5-flash")

async def generate_maze_creator() -> None:
    response = model.generate_content(prompt)
    maze_generation_script = response.text.strip()
    await run_generated_maze(runloop, maze_generation_script)

asyncio.run(generate_maze_creator())
```

```python OpenAI theme={null}
import asyncio
import os
from openai import AsyncOpenAI
from runloop_api_client import AsyncRunloopSDK

openai = AsyncOpenAI(api_key=os.environ["OPENAI_API_KEY"])
runloop = AsyncRunloopSDK()

async def generate_maze_creator() -> None:
    response = await openai.chat.completions.create(
        model="gpt-4o-mini",
        temperature=0,
        messages=[{"role": "user", "content": prompt}],
    )
    maze_generation_script = response.choices[0].message.content or ""
    await run_generated_maze(runloop, maze_generation_script)

asyncio.run(generate_maze_creator())
```

```python LangChain theme={null}
import asyncio
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from runloop_api_client import AsyncRunloopSDK

runloop = AsyncRunloopSDK()

async def generate_maze_creator() -> None:
    llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
    prompt_template = ChatPromptTemplate.from_messages([
        ("system", "Respond only with runnable Python code."),
        ("human", "{input}"),
    ])
    chain = prompt_template | llm | StrOutputParser()
    maze_generation_script = await chain.ainvoke({"input": prompt})
    await run_generated_maze(runloop, maze_generation_script)

asyncio.run(generate_maze_creator())
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.