Skip to content

Commit b291c98

Browse files
committed
feat: storm solution basic
1 parent 4e2f7d3 commit b291c98

File tree

8 files changed

+2888
-0
lines changed

8 files changed

+2888
-0
lines changed

storm-solution/cookbook/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Storm API Cookbook
2+
3+
Practical examples and tutorials for the Storm API - your RAG (Retrieval-Augmented Generation) platform.
4+
5+
## What is Storm API?
6+
7+
Storm API is the serverless RAG platform that enables:
8+
- Document learning and intelligent search
9+
- AI-powered chat with document context
10+
- Flexible document parsing with STORM Parse
11+
- Multi-tenant agent management
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Installation & Setup
2+
3+
Get started with Storm API in minutes.
4+
5+
## Prerequisites
6+
7+
- Python 3.7 or higher
8+
- pip package manager
9+
- Storm API key
10+
11+
## Installation
12+
13+
### Install Required Libraries
14+
15+
```bash
16+
pip install requests
17+
```
18+
19+
For advanced features:
20+
21+
```bash
22+
pip install requests pandas numpy jupyter
23+
```
24+
25+
## API Configuration
26+
27+
### Base URL
28+
29+
Storm API is available at:
30+
31+
```
32+
https://https://live-stargate.sionic.im
33+
```
34+
35+
### Authentication
36+
37+
Storm API uses header-based authentication:
38+
39+
```python
40+
headers = {
41+
"storm-api-key": "your-api-key-here"
42+
}
43+
```
44+
45+
## Environment Setup
46+
47+
### Using Environment Variables
48+
49+
Create a `.env` file:
50+
51+
```bash
52+
# .env
53+
STORM_API_KEY=your-api-key-here
54+
STORM_API_URL=https://https://live-stargate.sionic.im
55+
```
56+
57+
Load in Python:
58+
59+
```python
60+
import os
61+
from dotenv import load_dotenv
62+
63+
load_dotenv()
64+
65+
API_KEY = os.getenv("STORM_API_KEY")
66+
API_URL = os.getenv("STORM_API_URL", "https://https://live-stargate.sionic.im")
67+
```
68+
69+
### Configuration Class
70+
71+
```python
72+
class StormConfig:
73+
def __init__(self, api_key=None, api_url=None):
74+
self.api_key = api_key or os.getenv("STORM_API_KEY")
75+
self.api_url = api_url or os.getenv("STORM_API_URL", "https://https://live-stargate.sionic.im")
76+
77+
if not self.api_key:
78+
raise ValueError("Storm API key is required")
79+
80+
@property
81+
def headers(self):
82+
return {"storm-api-key": self.api_key}
83+
84+
# Usage
85+
config = StormConfig()
86+
```
87+
88+
## Verify Installation
89+
90+
Test your setup:
91+
92+
```python
93+
import requests
94+
95+
def test_connection(config):
96+
"""Test Storm API connection."""
97+
try:
98+
# Test with agent list endpoint
99+
response = requests.get(
100+
f"{config.api_url}/api/v2/agents",
101+
headers=config.headers
102+
)
103+
104+
if response.status_code == 200:
105+
print("✅ Successfully connected to Storm API")
106+
data = response.json()
107+
print(f"📊 Found {len(data['data']['data'])} agents")
108+
return True
109+
else:
110+
print(f"❌ Connection failed: {response.status_code}")
111+
return False
112+
except Exception as e:
113+
print(f"❌ Error: {e}")
114+
return False
115+
116+
# Test
117+
config = StormConfig()
118+
test_connection(config)
119+
```
120+
121+
## Next Steps
122+
123+
- [Authentication Guide](./02-authentication.md)
124+
- [Your First API Call](./03-first-api-call.ipynb)
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# Authentication
2+
3+
Storm API uses API key authentication passed in request headers.
4+
5+
## Authentication Method
6+
7+
### Header-Based Authentication
8+
9+
Include your API key in the `storm-api-key` header:
10+
11+
```python
12+
headers = {
13+
"storm-api-key": "your-api-key-here"
14+
}
15+
```
16+
17+
## Complete Example
18+
19+
```python
20+
import requests
21+
22+
class StormClient:
23+
def __init__(self, api_key, base_url="https://https://live-stargate.sionic.im"):
24+
self.api_key = api_key
25+
self.base_url = base_url
26+
self.headers = {"storm-api-key": api_key}
27+
28+
def get(self, endpoint, params=None):
29+
"""GET request with authentication."""
30+
url = f"{self.base_url}{endpoint}"
31+
response = requests.get(url, headers=self.headers, params=params)
32+
response.raise_for_status()
33+
return response.json()
34+
35+
def post(self, endpoint, json=None, data=None, files=None):
36+
"""POST request with authentication."""
37+
url = f"{self.base_url}{endpoint}"
38+
response = requests.post(
39+
url,
40+
headers=self.headers,
41+
json=json,
42+
data=data,
43+
files=files
44+
)
45+
response.raise_for_status()
46+
return response.json()
47+
48+
# Initialize client
49+
client = StormClient(api_key="your-api-key")
50+
51+
# Test authentication
52+
agents = client.get("/api/v2/agents")
53+
print(f"Authentication successful! Found {len(agents['data']['data'])} agents.")
54+
```
55+
56+
## Security Best Practices
57+
58+
### 1. Never Hard-code API Keys
59+
60+
**Bad:**
61+
```python
62+
API_KEY = "sk_live_abcd1234" # Never do this!
63+
```
64+
65+
**Good:**
66+
```python
67+
import os
68+
API_KEY = os.environ.get("STORM_API_KEY")
69+
```
70+
71+
### 2. Use Environment Variables
72+
73+
```bash
74+
# .bashrc or .zshrc
75+
export STORM_API_KEY="your-api-key-here"
76+
```
77+
78+
### 3. Secure Storage
79+
80+
For production applications:
81+
82+
```python
83+
import keyring
84+
85+
# Store API key securely
86+
keyring.set_password("storm-api", "api-key", "your-key")
87+
88+
# Retrieve API key
89+
api_key = keyring.get_password("storm-api", "api-key")
90+
```
91+
92+
## Error Handling
93+
94+
Handle authentication errors gracefully:
95+
96+
```python
97+
def make_authenticated_request(endpoint, api_key):
98+
"""Make request with proper error handling."""
99+
try:
100+
response = requests.get(
101+
f"https://https://live-stargate.sionic.im{endpoint}",
102+
headers={"storm-api-key": api_key}
103+
)
104+
105+
if response.status_code == 401:
106+
print("❌ Authentication failed. Check your API key.")
107+
return None
108+
elif response.status_code == 403:
109+
print("❌ Access forbidden. Check your permissions.")
110+
return None
111+
112+
response.raise_for_status()
113+
return response.json()
114+
115+
except requests.exceptions.RequestException as e:
116+
print(f"❌ Request failed: {e}")
117+
return None
118+
```
119+
120+
## Rate Limiting
121+
122+
Storm API implements rate limiting. Handle it properly:
123+
124+
```python
125+
import time
126+
127+
def request_with_retry(client, method, endpoint, max_retries=3, **kwargs):
128+
"""Make request with automatic retry on rate limit."""
129+
for attempt in range(max_retries):
130+
try:
131+
if method == "GET":
132+
return client.get(endpoint, **kwargs)
133+
elif method == "POST":
134+
return client.post(endpoint, **kwargs)
135+
except requests.exceptions.HTTPError as e:
136+
if e.response.status_code == 429: # Rate limited
137+
wait_time = int(e.response.headers.get("Retry-After", 60))
138+
print(f"Rate limited. Waiting {wait_time} seconds...")
139+
time.sleep(wait_time)
140+
else:
141+
raise
142+
143+
raise Exception("Max retries exceeded")
144+
```
145+
146+
## Testing Authentication
147+
148+
Quick test script:
149+
150+
```python
151+
#!/usr/bin/env python3
152+
"""Test Storm API authentication."""
153+
154+
import sys
155+
import requests
156+
import os
157+
158+
def test_auth(api_key=None):
159+
"""Test API authentication."""
160+
api_key = api_key or os.environ.get("STORM_API_KEY")
161+
162+
if not api_key:
163+
print("❌ No API key provided")
164+
print("Set STORM_API_KEY environment variable or pass as argument")
165+
return False
166+
167+
headers = {"storm-api-key": api_key}
168+
169+
try:
170+
response = requests.get(
171+
"https://https://live-stargate.sionic.im/api/v2/agents",
172+
headers=headers,
173+
params={"page": 1, "size": 1}
174+
)
175+
176+
if response.status_code == 200:
177+
print("✅ Authentication successful!")
178+
return True
179+
else:
180+
print(f"❌ Authentication failed: {response.status_code}")
181+
print(response.text)
182+
return False
183+
184+
except Exception as e:
185+
print(f"❌ Error: {e}")
186+
return False
187+
188+
if __name__ == "__main__":
189+
api_key = sys.argv[1] if len(sys.argv) > 1 else None
190+
test_auth(api_key)
191+
```
192+
193+
## Next Steps
194+
195+
- [Your First API Call](./03-first-api-call.ipynb) - Make your first Storm API request

0 commit comments

Comments
 (0)