or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

configuration.mdendpoint-management.mdindex.mdpod-management.mdserverless-worker.md

configuration.mddocs/

0

# Configuration

1

2

Credential management, API authentication, and configuration utilities for managing multiple profiles and environments. Includes user account management and SSH key configuration for secure access to RunPod resources.

3

4

## Capabilities

5

6

### Credential Management

7

8

Secure storage and management of API credentials with support for multiple profiles and environments.

9

10

```python { .api }

11

def set_credentials(

12

api_key: str,

13

profile: str = "default"

14

) -> None:

15

"""

16

Set API credentials for authentication.

17

18

Parameters:

19

- api_key: RunPod API key for authentication

20

- profile: Profile name for storing credentials (default: "default")

21

22

Credentials are stored securely in ~/.runpod/config.toml

23

"""

24

25

def get_credentials(profile: str = "default") -> dict:

26

"""

27

Get stored API credentials for a profile.

28

29

Parameters:

30

- profile: Profile name to retrieve (default: "default")

31

32

Returns:

33

dict: Credentials dictionary with api_key, or None if not found

34

Example: {"api_key": "your-api-key"}

35

"""

36

37

def check_credentials(profile: str = "default") -> bool:

38

"""

39

Check if API credentials are valid and working.

40

41

Parameters:

42

- profile: Profile name to check (default: "default")

43

44

Returns:

45

bool: True if credentials are valid, False otherwise

46

"""

47

```

48

49

### User Account Management

50

51

User profile and account settings management including SSH key configuration and account information retrieval.

52

53

```python { .api }

54

def get_user() -> dict:

55

"""

56

Get current user information and account details.

57

58

Returns:

59

dict: User information including account status, limits, and settings

60

Example:

61

{

62

"id": "user-123",

63

"email": "user@example.com",

64

"credits": 100.50,

65

"spendLimit": 500.00,

66

"notificationSettings": {...}

67

}

68

"""

69

70

def update_user_settings(pubkey: str) -> dict:

71

"""

72

Update user settings with SSH public key.

73

74

Parameters:

75

- pubkey: SSH public key for pod access

76

77

Returns:

78

dict: Updated user settings confirmation

79

"""

80

```

81

82

## Usage Examples

83

84

### Basic Credential Setup

85

86

```python

87

import runpod

88

89

# Set API credentials for default profile

90

runpod.set_credentials("your-api-key-here")

91

92

# Verify credentials work

93

if runpod.check_credentials():

94

print("Credentials are valid!")

95

else:

96

print("Invalid credentials")

97

98

# Get current credentials

99

creds = runpod.get_credentials()

100

if creds:

101

print(f"API key configured: {creds['api_key'][:8]}...")

102

else:

103

print("No credentials found")

104

```

105

106

### Multiple Profile Management

107

108

```python

109

import runpod

110

111

# Set up multiple profiles for different environments

112

runpod.set_credentials("prod-api-key", profile="production")

113

runpod.set_credentials("dev-api-key", profile="development")

114

runpod.set_credentials("test-api-key", profile="testing")

115

116

# Check each profile

117

profiles = ["production", "development", "testing"]

118

for profile in profiles:

119

is_valid = runpod.check_credentials(profile)

120

print(f"{profile}: {'✓' if is_valid else '✗'}")

121

122

# Use specific profile

123

runpod.profile = "development"

124

dev_creds = runpod.get_credentials("development")

125

```

126

127

### User Account Management

128

129

```python

130

import runpod

131

132

# Set credentials first

133

runpod.set_credentials("your-api-key")

134

135

# Get user information

136

user_info = runpod.get_user()

137

print(f"User: {user_info['email']}")

138

print(f"Credits: ${user_info['credits']:.2f}")

139

print(f"Spend Limit: ${user_info['spendLimit']:.2f}")

140

141

# Update SSH key for pod access

142

ssh_public_key = open("~/.ssh/id_rsa.pub").read().strip()

143

result = runpod.update_user_settings(

144

public_key=ssh_public_key,

145

spend_limit=1000.00,

146

notification_email="alerts@mycompany.com"

147

)

148

print("Settings updated:", result)

149

```

150

151

### Environment-Based Configuration

152

153

```python

154

import runpod

155

import os

156

157

def configure_runpod():

158

"""Configure RunPod based on environment."""

159

160

# Check for environment variable first

161

api_key = os.environ.get("RUNPOD_API_KEY")

162

163

if api_key:

164

print("Using API key from environment")

165

runpod.set_credentials(api_key)

166

else:

167

# Try to load from stored credentials

168

creds = runpod.get_credentials()

169

if not creds:

170

raise ValueError("No API key found. Set RUNPOD_API_KEY or use runpod.set_credentials()")

171

172

# Verify credentials

173

if not runpod.check_credentials():

174

raise ValueError("Invalid API credentials")

175

176

print("RunPod configured successfully")

177

return True

178

179

# Usage in application

180

try:

181

configure_runpod()

182

183

# Now you can use RunPod API

184

pods = runpod.get_pods()

185

print(f"Found {len(pods)} pods")

186

187

except Exception as e:

188

print(f"Configuration failed: {e}")

189

```

190

191

### Configuration with Profile Switching

192

193

```python

194

import runpod

195

196

class RunPodManager:

197

"""Manage RunPod configurations with profile switching."""

198

199

def __init__(self, default_profile="default"):

200

self.current_profile = default_profile

201

self.profiles = {}

202

203

def add_profile(self, name, api_key):

204

"""Add a new profile."""

205

runpod.set_credentials(api_key, profile=name)

206

self.profiles[name] = api_key

207

print(f"Added profile: {name}")

208

209

def switch_profile(self, profile_name):

210

"""Switch to a different profile."""

211

if profile_name not in self.profiles:

212

creds = runpod.get_credentials(profile_name)

213

if not creds:

214

raise ValueError(f"Profile '{profile_name}' not found")

215

216

# Update global profile

217

runpod.profile = profile_name

218

self.current_profile = profile_name

219

220

# Verify the switch worked

221

if runpod.check_credentials(profile_name):

222

print(f"Switched to profile: {profile_name}")

223

else:

224

raise ValueError(f"Invalid credentials for profile: {profile_name}")

225

226

def list_profiles(self):

227

"""List all available profiles."""

228

print("Available profiles:")

229

for profile in self.profiles:

230

status = "✓" if runpod.check_credentials(profile) else "✗"

231

current = " (current)" if profile == self.current_profile else ""

232

print(f" {profile}: {status}{current}")

233

234

# Usage

235

manager = RunPodManager()

236

237

# Add profiles

238

manager.add_profile("production", "prod-api-key")

239

manager.add_profile("staging", "staging-api-key")

240

241

# Switch between environments

242

manager.switch_profile("production")

243

prod_pods = runpod.get_pods()

244

245

manager.switch_profile("staging")

246

staging_pods = runpod.get_pods()

247

248

# List all profiles

249

manager.list_profiles()

250

```

251

252

### Global Configuration Variables

253

254

```python

255

import runpod

256

257

# Access global configuration variables

258

print(f"Current profile: {runpod.profile}")

259

print(f"API key set: {'Yes' if runpod.api_key else 'No'}")

260

print(f"SSH key path: {runpod.SSH_KEY_PATH}")

261

print(f"Endpoint base URL: {runpod.endpoint_url_base}")

262

263

# Modify global settings

264

runpod.profile = "production"

265

266

# Custom endpoint URL (for testing or enterprise)

267

import os

268

os.environ["RUNPOD_ENDPOINT_BASE_URL"] = "https://api.custom-runpod.com/v2"

269

270

# Force reload of global variables

271

import importlib

272

importlib.reload(runpod)

273

274

print(f"New endpoint URL: {runpod.endpoint_url_base}")

275

```

276

277

### Configuration Validation

278

279

```python

280

import runpod

281

import sys

282

283

def validate_configuration():

284

"""Comprehensive configuration validation."""

285

286

issues = []

287

288

# Check API key

289

if not runpod.api_key:

290

issues.append("No API key configured")

291

elif not runpod.check_credentials():

292

issues.append("Invalid API key")

293

294

# Check user account

295

try:

296

user = runpod.get_user()

297

if user.get("credits", 0) < 1:

298

issues.append("Low account credits")

299

except Exception as e:

300

issues.append(f"Cannot access user account: {e}")

301

302

# Check SSH key path

303

import os

304

if not os.path.exists(runpod.SSH_KEY_PATH):

305

issues.append(f"SSH key directory not found: {runpod.SSH_KEY_PATH}")

306

307

# Report results

308

if issues:

309

print("Configuration issues found:")

310

for issue in issues:

311

print(f" ⚠️ {issue}")

312

return False

313

else:

314

print("✅ Configuration is valid")

315

return True

316

317

# Run validation

318

if __name__ == "__main__":

319

if not validate_configuration():

320

sys.exit(1)

321

322

print("Ready to use RunPod!")

323

```