Build intelligent applications with Claude 3.5 Sonnet and other Anthropic models.
npm install @anthropic-ai/sdk @cognitora/sdk
1import Anthropic from '@anthropic-ai/sdk';
2import { Cognitora } from '@cognitora/sdk';
3
4const anthropic = new Anthropic({
5 apiKey: process.env.ANTHROPIC_API_KEY,
6});
7const cognitora = new Cognitora({
8 apiKey: process.env.COGNITORA_API_KEY,
9 baseURL: 'https://api.cognitora.dev'
10});
11
12async function runClaudeCodeInterpreter(userQuery: string) {
13 const session = await cognitora.codeInterpreter.createSession({
14 language: 'python',
15 timeout_minutes: 30,
16 resources: {
17 cpu_cores: 1.0,
18 memory_mb: 512,
19 storage_gb: 5
20 }
21 });
22
23 const systemPrompt = `You have access to a Python code execution environment.
24Format your code in \`\`\`python code blocks.`;
25
26 const message = await anthropic.messages.create({
27 model: 'claude-3-5-sonnet-20241022',
28 max_tokens: 4000,
29 system: systemPrompt,
30 messages: [{ role: 'user', content: userQuery }]
31 });
32
33 const response = message.content[0];
34
35 if (response.type === 'text') {
36 const codeMatch = response.text.match(/```python\n([\s\S]*?)\n```/);
37
38 if (codeMatch) {
39 const code = codeMatch[1];
40
41 const execution = await cognitora.codeInterpreter.execute({
42 code,
43 language: 'python',
44 session_id: session.data.session_id,
45 timeout_seconds: 30
46 });
47
48 return {
49 claudeResponse: response.text,
50 code,
51 result: execution.data.outputs,
52 status: execution.data.status,
53 execution_time: execution.data.execution_time_ms
54 };
55 }
56 }
57}
Get started with Anthropic Claude and Cognitora in minutes. Secure, scalable, and ready for anything.