Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Works in Cursor, Cline, Continue and OpenClaw through the OpenAI-compatible endp
| [`curl/models.sh`](curl/models.sh) | List the models your key can call |
| [`cursor/README.md`](cursor/README.md) | Cursor, Cline and Continue settings |
| [`ollama-on-rented-gpu/README.md`](ollama-on-rented-gpu/README.md) | Calling Ollama or vLLM on a GPU you rented, via its public HTTPS endpoint |
| [`ai-sdk/`](ai-sdk/README.md) | Vercel AI SDK (`@ai-sdk/openai-compatible`): generateText and streamText |

## Setup

Expand Down
71 changes: 71 additions & 0 deletions ai-sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Vercel AI SDK with CloudGPU

CloudGPU's OpenAI-compatible model API (`https://cloudgpu.app/v1`) used through the Vercel AI SDK's [`@ai-sdk/openai-compatible`](https://ai-sdk.dev/providers/openai-compatible-providers) provider. Two examples: `generateText` and `streamText`.

## Install

```bash
npm install ai @ai-sdk/openai-compatible
```

## API key

Create a key at https://cloudgpu.app/api/console, then:

```bash
export CLOUDGPU_API_KEY=...
```

## Provider

```js
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';

const cloudgpu = createOpenAICompatible({
name: 'cloudgpu',
apiKey: process.env.CLOUDGPU_API_KEY,
baseURL: 'https://cloudgpu.app/v1',
});
```

## Examples

`generate.mjs` calls `generateText` with `kimi-k3` and prints the text:

```bash
npm run generate
```

```js
const { text } = await generateText({
model: cloudgpu.chatModel('kimi-k3'),
prompt: 'Write a one-sentence summary of what a GPU does.',
});
```

`stream.mjs` calls `streamText` with `glm-5.2` and prints each chunk of `textStream`. It sets `includeUsage: true` on the provider so usage is returned with the stream:

```bash
npm run stream
```

```js
const result = streamText({
model: cloudgpu.chatModel('glm-5.2'),
prompt: 'Explain what an HTTP API gateway does in three short sentences.',
});
for await (const chunk of result.textStream) process.stdout.write(chunk);
```

## Switching models

Pass a different model ID to `cloudgpu.chatModel(...)`, for example `kimi-k3`, `glm-5.2`, `deepseek-v4.1-flash` or `deepseek-v4-pro`. The current list is returned by:

```bash
curl https://cloudgpu.app/v1/models -H "Authorization: Bearer $CLOUDGPU_API_KEY"
```

## Links

- CloudGPU API docs: https://cloudgpu.app/api/docs
- AI SDK OpenAI Compatible provider docs: https://ai-sdk.dev/providers/openai-compatible-providers
20 changes: 20 additions & 0 deletions ai-sdk/generate.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { generateText } from 'ai';

if (!process.env.CLOUDGPU_API_KEY) {
console.error('CLOUDGPU_API_KEY is not set. Create a key at https://cloudgpu.app/api/console and run: export CLOUDGPU_API_KEY=...');
process.exit(1);
}

const cloudgpu = createOpenAICompatible({
name: 'cloudgpu',
apiKey: process.env.CLOUDGPU_API_KEY,
baseURL: 'https://cloudgpu.app/v1',
});

const { text } = await generateText({
model: cloudgpu.chatModel('kimi-k3'),
prompt: 'Write a one-sentence summary of what a GPU does.',
});

console.log(text);
13 changes: 13 additions & 0 deletions ai-sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "cloudgpu-ai-sdk-example",
"private": true,
"type": "module",
"scripts": {
"generate": "node generate.mjs",
"stream": "node stream.mjs"
},
"dependencies": {
"@ai-sdk/openai-compatible": "^2.0.0",
"ai": "^6.0.0"
}
}
24 changes: 24 additions & 0 deletions ai-sdk/stream.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { streamText } from 'ai';

if (!process.env.CLOUDGPU_API_KEY) {
console.error('CLOUDGPU_API_KEY is not set. Create a key at https://cloudgpu.app/api/console and run: export CLOUDGPU_API_KEY=...');
process.exit(1);
}

const cloudgpu = createOpenAICompatible({
name: 'cloudgpu',
apiKey: process.env.CLOUDGPU_API_KEY,
baseURL: 'https://cloudgpu.app/v1',
includeUsage: true,
});

const result = streamText({
model: cloudgpu.chatModel('glm-5.2'),
prompt: 'Explain what an HTTP API gateway does in three short sentences.',
});

for await (const chunk of result.textStream) {
process.stdout.write(chunk);
}
process.stdout.write('\n');
Loading