opencloud-platform-sdk
v1.3.0
Published
Official SDK for OpenCloud - AI App Marketplace
Downloads
298
Maintainers
Readme
@opencloud/sdk
Official SDK for OpenCloud - The AI App Marketplace with pay-per-use model.
Build AI-powered apps that automatically handle payments and AI API calls through OpenCloud's platform.
Features
- ✅ Call 100+ AI models (GPT-4, Claude, Gemini, Llama, etc.) via OpenRouter
- ✅ Automatic payment processing (70% to creators, 30% to platform)
- ✅ No API keys needed - OpenCloud handles everything
- ✅ TypeScript support with full type definitions
- ✅ Works in browsers and Node.js
- ✅ Zero dependencies
Installation
npm install @opencloud/sdk
# or
pnpm add @opencloud/sdk
# or
yarn add @opencloud/sdkQuick Start
For React/Next.js Apps
import { opencloud } from '@opencloud/sdk';
// Initialize with your app ID
opencloud.init({ appId: 'your-app-slug' });
// Call AI models
const response = await opencloud.callAI({
model: 'openai/gpt-4',
prompt: 'Write a tagline for my startup'
});
console.log(response.text); // AI-generated response
console.log(response.cost); // $0.10 (or your app's price per use)For HTML/Vanilla JS
<script src="https://opencloud.com/sdk/platform-sdk.js"></script>
<script>
PlatformSDK.init({ appId: 'your-app-slug' });
async function generate() {
const result = await PlatformSDK.callAI({
model: 'anthropic/claude-3-5-sonnet',
prompt: 'Generate a logo description'
});
console.log(result.text);
}
</script>API Reference
opencloud.init(config)
Initialize the SDK with your app configuration.
opencloud.init({
appId: 'your-app-slug', // Required: Your app's unique identifier
apiUrl: 'https://opencloud.com' // Optional: Platform URL (defaults to current origin)
});opencloud.callAI(params)
Call an AI model through OpenCloud's platform.
const response = await opencloud.callAI({
model: 'openai/gpt-4', // Required: Model identifier
prompt: 'Your prompt here', // Required: The prompt to send
options: { // Optional: Additional model parameters
temperature: 0.7,
max_tokens: 1000
}
});
// Response structure:
{
success: true,
text: "AI-generated response...",
usage: {
promptTokens: 10,
completionTokens: 50,
totalTokens: 60
},
cost: 0.10, // Amount charged to user
model: "openai/gpt-4"
}opencloud.getBalance()
Get the current user's token balance.
const balance = await opencloud.getBalance();
console.log(`Balance: $${balance}`);opencloud.requestTopUp()
Request the user to purchase more tokens (opens payment dialog).
try {
await opencloud.callAI({...});
} catch (error) {
if (error.message.includes('Insufficient balance')) {
await opencloud.requestTopUp();
}
}Supported AI Models
OpenCloud uses OpenRouter, giving you access to 100+ models:
OpenAI:
openai/gpt-4openai/gpt-4-turboopenai/gpt-3.5-turbo
Anthropic:
anthropic/claude-3-5-sonnetanthropic/claude-3-haikuanthropic/claude-3-opus
Google:
google/gemini-progoogle/gemini-pro-vision
Meta:
meta-llama/llama-3-70bmeta-llama/llama-3-8b
And many more! See OpenRouter docs for full list.
Example Apps
Text Summarizer
import { opencloud } from '@opencloud/sdk';
opencloud.init({ appId: 'text-summarizer' });
async function summarize(text: string) {
const response = await opencloud.callAI({
model: 'anthropic/claude-3-haiku', // Fast and cheap
prompt: `Summarize this text in 3 bullet points:\n\n${text}`
});
return response.text;
}Image Description Generator
import { opencloud } from '@opencloud/sdk';
opencloud.init({ appId: 'image-describer' });
async function describeImage(imageUrl: string) {
const response = await opencloud.callAI({
model: 'google/gemini-pro-vision',
prompt: 'Describe this image in detail',
options: {
image: imageUrl
}
});
return response.text;
}Revenue Model
OpenCloud uses a 70/30 revenue split:
- 70% goes to you (the app creator)
- 30% goes to OpenCloud (platform fee)
Example:
User pays: $0.10 per use
AI cost: -$0.03 (OpenAI API)
Net revenue: $0.07
├─ You get: $0.049 (70%)
└─ Platform: $0.021 (30%)TypeScript Support
Full TypeScript definitions included:
import {
opencloud,
OpenCloudSDK,
AICallParams,
AIResponse,
OpenCloudConfig
} from '@opencloud/sdk';
const params: AICallParams = {
model: 'openai/gpt-4',
prompt: 'Hello world'
};
const response: AIResponse = await opencloud.callAI(params);Publishing Your App
- Build your app with the SDK
- Go to opencloud.com/publish
- Upload your app or connect GitHub
- Set pricing and details
- Test with $5 free credits
- Publish to marketplace!
Support
License
MIT © OpenCloud
