vastai-hello-world

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Vast.ai Hello World

Vast.ai Hello World

Overview

概述

Minimal working example demonstrating core Vast.ai functionality.
演示Vast.ai核心功能的最小可运行示例。

Prerequisites

前置条件

  • Completed
    vastai-install-auth
    setup
  • Valid API credentials configured
  • Development environment ready
  • 已完成
    vastai-install-auth
    配置
  • 已配置有效的API凭证
  • 开发环境准备就绪

Instructions

操作步骤

Step 1: Create Entry File

步骤1:创建入口文件

Create a new file for your hello world example.
为你的hello world示例新建一个文件。

Step 2: Import and Initialize Client

步骤2:导入并初始化客户端

typescript
import { Vast.aiClient } from '@vastai/sdk';

const client = new Vast.aiClient({
  apiKey: process.env.VASTAI_API_KEY,
});
typescript
import { Vast.aiClient } from '@vastai/sdk';

const client = new Vast.aiClient({
  apiKey: process.env.VASTAI_API_KEY,
});

Step 3: Make Your First API Call

步骤3:发起你的首次API调用

typescript
async function main() {
  // Your first API call here
}

main().catch(console.error);
typescript
async function main() {
  // Your first API call here
}

main().catch(console.error);

Output

输出

  • Working code file with Vast.ai client initialization
  • Successful API response confirming connection
  • Console output showing:
Success! Your Vast.ai connection is working.
  • 完成Vast.ai客户端初始化的可运行代码文件
  • 确认连接成功的API响应
  • 控制台输出内容如下:
Success! Your Vast.ai connection is working.

Error Handling

错误处理

ErrorCauseSolution
Import ErrorSDK not installedVerify with
npm list
or
pip show
Auth ErrorInvalid credentialsCheck environment variable is set
TimeoutNetwork issuesIncrease timeout or check connectivity
Rate LimitToo many requestsWait and retry with exponential backoff
错误原因解决方案
导入错误SDK未安装使用
npm list
pip show
验证安装状态
认证错误凭证无效检查环境变量是否正确设置
超时错误网络问题增加超时时间或检查网络连接
速率限制请求次数过多等待后使用指数退避策略重试

Examples

示例

TypeScript Example

TypeScript示例

typescript
import { Vast.aiClient } from '@vastai/sdk';

const client = new Vast.aiClient({
  apiKey: process.env.VASTAI_API_KEY,
});

async function main() {
  // Your first API call here
}

main().catch(console.error);
typescript
import { Vast.aiClient } from '@vastai/sdk';

const client = new Vast.aiClient({
  apiKey: process.env.VASTAI_API_KEY,
});

async function main() {
  // Your first API call here
}

main().catch(console.error);

Python Example

Python示例

python
from vastai import Vast.aiClient

client = Vast.aiClient()
python
from vastai import Vast.aiClient

client = Vast.aiClient()

Your first API call here

Your first API call here

undefined
undefined

Resources

相关资源

Next Steps

后续步骤

Proceed to
vastai-local-dev-loop
for development workflow setup.
前往
vastai-local-dev-loop
完成开发工作流配置。