aikutty-sdk
v1.0.0
Published
AIKUTTY - TypeScript & React Native AI Development SDK
Downloads
95
Maintainers
Readme
@aikutty/sdk
Official JavaScript/TypeScript SDK for Aikutty AI Code Development Platform.
Installation
npm install @aikutty/sdkor
yarn add @aikutty/sdkQuick Start
JavaScript/TypeScript (Node.js or Browser)
import { AikuttyClient } from '@aikutty/sdk';
const client = new AikuttyClient({
tenantId: 'your-tenant-id',
apiEndpoint: 'https://api.aikutty.com' // optional
});
// Simple chat
const response = await client.chat('How do I create a React component?');
console.log(response.reply);
// Generate code
const code = await client.generateCode('function to sort array by date', 'javascript');
console.log(code);
// Explain code
const explanation = await client.explainCode('const [state, setState] = useState(0)');
console.log(explanation);
// Review code
const review = await client.reviewCode('function validateEmail(email) { return email.includes("@") }');
console.log(review);
// Check credits
const credits = await client.getCredits();
console.log(`Remaining credits: ${credits}`);React
import { AikuttyProvider, useAikutty, AikuttyChat } from '@aikutty/sdk/react';
// Wrap your app with the provider
function App() {
return (
<AikuttyProvider tenantId="your-tenant-id">
<MyComponent />
</AikuttyProvider>
);
}
// Use the hook in your components
function MyComponent() {
const { sendMessage, messages, isLoading, credits } = useAikutty();
const handleAsk = async () => {
const response = await sendMessage('Explain async/await');
console.log(response);
};
return (
<div>
<p>Credits: {credits}</p>
<button onClick={handleAsk} disabled={isLoading}>
Ask Question
</button>
</div>
);
}
// Or use the pre-built chat component
function ChatPage() {
return (
<AikuttyProvider tenantId="your-tenant-id">
<AikuttyChat
showCredits={true}
placeholder="Ask anything..."
/>
</AikuttyProvider>
);
}API Reference
AikuttyClient
Constructor
new AikuttyClient(config: AikuttyConfig)Config:
tenantId(required): Your unique tenant identifierapiEndpoint(optional): API endpoint URL (default: https://api.aikutty.com)timeout(optional): Request timeout in ms (default: 60000)
Methods
chat(message)
Send a chat message and get a response.
const response = await client.chat('How do I use React hooks?');
// or with full options
const response = await client.chat({
messages: [
{ role: 'user', content: 'Hello' }
],
stream: false,
maxTokens: 2048
});Returns: ChatResponse
{
reply: string;
usage: {
inputTokens: number;
outputTokens: number;
totalTokens: number;
};
model: string;
requestId: string;
}generateCode(prompt, language)
Generate code from a natural language prompt.
const code = await client.generateCode(
'binary search function',
'python'
);Returns: string (the generated code)
explainCode(code)
Get an explanation of code.
const explanation = await client.explainCode(`
const [count, setCount] = useState(0);
`);Returns: string (the explanation)
reviewCode(code)
Review code for bugs and improvements.
const review = await client.reviewCode(`
function divide(a, b) {
return a / b;
}
`);Returns: string (the review)
getBilling()
Get billing information.
const billing = await client.getBilling();
// { plan: 'free', credits: 15, totalConsumed: 7 }Returns: BillingInfo
getCredits()
Get remaining credits.
const credits = await client.getCredits();
// 15Returns: number
clearHistory()
Clear conversation history.
client.clearHistory();getHistory()
Get conversation history.
const history = client.getHistory();
// [{ role: 'user', content: '...' }, ...]Returns: Message[]
setSystemMessage(content)
Set a system message for the conversation.
client.setSystemMessage('You are a Python expert. Provide concise answers.');React Hooks
useAikutty()
Access Aikutty functionality in React components.
const {
client, // AikuttyClient instance
messages, // Message[]
isLoading, // boolean
credits, // number | null
sendMessage, // (content: string) => Promise<ChatResponse | null>
generateCode, // (prompt: string, language?: string) => Promise<string | null>
clearHistory, // () => void
refreshCredits // () => Promise<void>
} = useAikutty();Free Credits
New users receive 22 free credits to try Aikutty. Each request consumes 1 credit.
Error Handling
try {
const response = await client.chat('Hello');
} catch (error) {
if (error.message.includes('Credits exhausted')) {
console.log('Please upgrade your plan');
} else {
console.error('Error:', error);
}
}TypeScript Support
The SDK is written in TypeScript and includes full type definitions.
License
MIT
Support
- Website: https://aikutty.com
- Email: [email protected]
- GitHub: https://github.com/aikutty/aikutty-sdk
