vastai-hello-world
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseVast.ai Hello World
Vast.ai Hello World
Overview
概述
Minimal working example demonstrating core Vast.ai functionality.
演示Vast.ai核心功能的最小可运行示例。
Prerequisites
前置条件
- Completed setup
vastai-install-auth - 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
错误处理
| Error | Cause | Solution |
|---|---|---|
| Import Error | SDK not installed | Verify with |
| Auth Error | Invalid credentials | Check environment variable is set |
| Timeout | Network issues | Increase timeout or check connectivity |
| Rate Limit | Too many requests | Wait and retry with exponential backoff |
| 错误 | 原因 | 解决方案 |
|---|---|---|
| 导入错误 | SDK未安装 | 使用 |
| 认证错误 | 凭证无效 | 检查环境变量是否正确设置 |
| 超时错误 | 网络问题 | 增加超时时间或检查网络连接 |
| 速率限制 | 请求次数过多 | 等待后使用指数退避策略重试 |
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
undefinedundefinedResources
相关资源
Next Steps
后续步骤
Proceed to for development workflow setup.
vastai-local-dev-loop前往完成开发工作流配置。
vastai-local-dev-loop