Getting Started
Cognitora is the enterprise cloud infrastructure designed exclusively for AI agents. Learn how to get started with our SDKs and APIs.
This guide will walk you through the first steps to get you started with Cognitora.
Quick Start
The quickest way to get started is to use one of our official SDKs. We have comprehensive examples for Python, JavaScript/TypeScript, and direct API access with cURL.
Get your API Key: Sign up on the Cognitora Dashboard to get your API key. All API requests need to be authenticated with an API key.
Choose your language and try these examples:
Python:
pip install cognitora
from cognitora import Cognitora
# Initialize client
client = Cognitora(api_key="your_api_key_here")
# Code Interpreter - Perfect for AI agents
result = client.code_interpreter.execute(
code="print('Hello from Cognitora!')\nresult = 2 + 2\nprint(f'2 + 2 = {result}')",
language="python"
)
print(result.output)
# Containers - Perfect for custom applications
container = client.containers.create_container(
image="python:3.11-slim",
command=["python", "-c", "print('Hello from container!')"]
)
print(container.status)
JavaScript/TypeScript:
npm install @cognitora/sdk
import { Cognitora } from '@cognitora/sdk';
// Initialize client
const client = new Cognitora({
apiKey: 'your_api_key_here',
});
// Code Interpreter - Perfect for AI agents
const result = await client.codeInterpreter.execute({
code: `console.log('Hello from Cognitora!');
const result = 2 + 2;
console.log(\`2 + 2 = \${result}\`);`,
language: 'javascript'
});
console.log(result.output);
// Containers - Perfect for custom applications
const container = await client.containers.createContainer({
image: 'node:18-alpine',
command: ['node', '-e', "console.log('Hello from container!')"],
executionType: 'COMMAND'
});
console.log(container.status);
cURL:
# Get your API key from https://www.cognitora.dev/home/api-keys
export COGNITORA_API_KEY="your_api_key_here"
# Code Interpreter - Perfect for AI agents
curl -X POST "https://api.cognitora.dev/api/v1/interpreter/execute" \
-H "Authorization: Bearer $COGNITORA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"code": "print(\"Hello from Cognitora!\")\nresult = 2 + 2\nprint(f\"2 + 2 = {result}\")",
"language": "python"
}'
# Containers - Perfect for custom applications
curl -X POST "https://api.cognitora.dev/api/v1/compute/containers" \
-H "Authorization: Bearer $COGNITORA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"image": "python:3.11-slim",
"command": ["python", "-c", "print(\"Hello from container!\")"]
}'
Code Interpreter vs Containers: When to Use Each
Cognitora provides two main execution environments, each optimized for different use cases:
🧠 Code Interpreter API
Best for: AI agents, interactive code execution, and data analysis
Feature | Details |
---|---|
Purpose | Interactive code execution for AI agents |
Languages | Python, JavaScript, Bash |
Sessions | Persistent sessions maintain state between executions |
Networking | Enabled by default - needs package installs, data fetching |
Use Cases | Data analysis, AI agent tools, interactive computing |
API Path | /api/v1/interpreter/ |
Security Model | Sandboxed with internet access for functionality |
Perfect for:
- AI agents executing dynamic code
- Data science and analysis workflows
- Interactive coding environments
- Code generation and testing
🐳 Containers API
Best for: Custom applications, long-running jobs, and production workloads
Feature | Details |
---|---|
Purpose | Run any Docker container with full control |
Images | Any Docker image from public/private registries |
Execution | Custom commands and entry points |
Networking | Disabled by default - security-first approach |
Use Cases | Batch processing, custom environments, microservices |
API Path | /api/v1/compute/containers/ |
Security Model | Isolated by default, networking optional |
Perfect for:
- Running existing Docker applications
- Batch processing and ETL jobs
- Custom runtime environments
- Production workloads requiring specific dependencies
🔒 Security Defaults
Service | Default Networking | Rationale |
---|---|---|
Code Interpreter | true (enabled) | Needs package installs, API calls, data fetching |
Containers | false (disabled) | Security-first: isolated execution by default |
Example: Comparing Both APIs
Here's how to use both Code Interpreter and Containers APIs with our Python SDK:
from cognitora import Cognitora
# Initialize client
cognitora = Cognitora(
api_key="your_api_key_here",
base_url="https://api.cognitora.dev"
)
# 🧠 CODE INTERPRETER: Interactive code execution
# Perfect for AI agents, data analysis, dynamic code execution
print("=== Code Interpreter Example ===")
result = cognitora.code_interpreter.execute(
code='''
import requests
import json
# Fetch some data (networking enabled by default)
response = requests.get('https://api.github.com/users/octocat')
user_data = response.json()
print(f"GitHub user: {user_data['name']}")
print(f"Public repos: {user_data['public_repos']}")
print("Code Interpreter: Perfect for dynamic, interactive code!")
''',
language="python",
networking=True # Default: enabled for code interpreter
)
print(f"Status: {result.data.status}")
for output in result.data.outputs:
print(f"{output.type}: {output.content}")
# 🐳 CONTAINERS: Run custom Docker containers
# Perfect for production workloads, batch jobs, custom environments
print("\n=== Containers Example ===")
container = cognitora.containers.create_container(
image="docker.io/library/python:3.11-slim",
command=["python", "-c", '''
print("Hello from a secure Docker container!")
print("Containers: Perfect for production workloads!")
import os
print(f"Container hostname: {os.uname().nodename}")
'''],
cpu_cores=1.0,
memory_mb=512,
max_cost_credits=10,
storage_gb=5,
networking=False # Default: disabled for security
)
print(f"Container ID: {container.id}")
print(f"Status: {container.status}")
# Wait for completion and get logs
import time
time.sleep(5) # Wait for execution
logs = cognitora.containers.get_container_logs(container.id)
print(f"Container output: {logs.logs}")
Key Differences Summary:
- Code Interpreter: Use for AI agents, interactive coding, data analysis
- Containers: Use for production apps, custom Docker images, batch processing
- Security: Code Interpreter has networking ON, Containers have networking OFF by default
For more advanced use-cases, please check the documentation for our SDKs.
Code Interpreter API Examples
The Code Interpreter API allows you to execute code in a sandboxed environment, supporting various languages like Python, JavaScript, and Bash. Networking is enabled by default to support package installations and data fetching.
cURL Example
curl -X POST https://api.cognitora.dev/api/v1/interpreter/execute \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <api-key>" \
-d '{
"language": "python",
"code": "import requests; print(f\"GitHub API Status: {requests.get('https://api.github.com').status_code}\")",
"networking": true
}'
Python SDK Example
from cognitora import Cognitora
client = Cognitora(
api_key="your_api_key",
base_url="https://api.cognitora.dev"
)
# Code Interpreter with networking enabled (default)
result = client.code_interpreter.execute(
code="""
import pandas as pd
import requests
# Fetch data from an API (requires networking)
response = requests.get('https://api.coindesk.com/v1/bpi/currentprice.json')
bitcoin_data = response.json()
print(f"Bitcoin price: {bitcoin_data['bpi']['USD']['rate']}")
print("Code Interpreter: Perfect for data analysis with internet access!")
""",
language="python",
networking=True # Default: enabled for code interpreter
)
print(f"Status: {result.data.status}")
for output in result.data.outputs:
print(f"{output.type}: {output.content}")
JavaScript/TypeScript SDK Example
import { Cognitora } from '@cognitora/sdk';
const client = new Cognitora({
apiKey: 'your_api_key',
baseURL: 'https://api.cognitora.dev'
});
// Code Interpreter with networking enabled (default)
const result = await client.codeInterpreter.execute({
code: `
const https = require('https');
// Fetch data from an API (requires networking)
https.get('https://api.github.com/zen', (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
console.log('GitHub Zen:', data);
console.log('Code Interpreter: Perfect for interactive coding with internet access!');
});
}).on('error', (err) => {
console.error('Error:', err.message);
});
`,
language: 'javascript',
networking: true // Default: enabled for code interpreter
});
console.log(`Status: ${result.data.status}`);
result.data.outputs.forEach(output => {
console.log(`${output.type}: ${output.content}`);
});
Containers API Examples
The Containers API allows you to run any Docker container with custom commands and environments. Networking is disabled by default for security-first isolated execution.
Python SDK - Secure Container Example
from cognitora import Cognitora
client = Cognitora(
api_key="your_api_key",
base_url="https://api.cognitora.dev"
)
# Secure container execution (networking disabled by default)
container = client.containers.create_container(
image="docker.io/library/python:3.11-slim",
command=["python", "-c", """
import os
import math
print("Hello from a secure Docker container!")
print(f"Container hostname: {os.uname().nodename}")
print(f"Pi calculation: {math.pi * 2}")
print("Containers: Perfect for secure, isolated production workloads!")
"""],
cpu_cores=1.0,
memory_mb=512,
storage_gb=5,
max_cost_credits=10,
networking=False # Default: disabled for security
)
print(f"Container ID: {container.id}")
print(f"Status: {container.status}")
JavaScript SDK - Container with Custom Image
import { Cognitora } from '@cognitora/sdk';
const client = new Cognitora({
apiKey: 'your_api_key',
baseURL: 'https://api.cognitora.dev'
});
// Run a custom Node.js container (secure by default)
const container = await client.containers.createContainer({
image: 'docker.io/library/node:18-alpine',
command: ['node', '-e', `
console.log('Hello from a secure Node.js container!');
console.log('Hostname:', require('os').hostname());
console.log('Node version:', process.version);
console.log('Containers: Perfect for production microservices!');
`],
cpuCores: 1.0,
memoryMb: 512,
storageGb: 5,
maxCostCredits: 10,
networking: false // Default: disabled for security
});
console.log(`Container ID: ${container.id}`);
console.log(`Status: ${container.status}`);
// Enable networking when needed (e.g., for API calls)
const networkContainer = await client.containers.createContainer({
image: 'docker.io/library/node:18-alpine',
command: ['node', '-e', `
const https = require('https');
https.get('https://api.github.com/zen', (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => console.log('GitHub Zen:', data));
});
`],
cpuCores: 1.0,
memoryMb: 512,
maxCostCredits: 10,
networking: true // Explicitly enable when needed
});
Next Steps
Ready to build with Cognitora? Explore these enterprise guides:
- Containers API - Provision and manage enterprise resources
- SDKs - Learn more about our SDKs for Python and JavaScript/TypeScript.
- Code Interpreter API - Execute code in a sandboxed environment.