AJ STUDIOZ commited on
Commit
dfa2ec3
·
1 Parent(s): bf11ea2

Fixed: Use text_generation instead of chat_completion + Added Anthropic Claude API support

Browse files
Files changed (3) hide show
  1. README.md +154 -16
  2. SUCCESS-SUMMARY.md +242 -0
  3. app.py +144 -28
README.md CHANGED
@@ -10,30 +10,76 @@ license: mit
10
 
11
  # AJ STUDIOZ API - Enterprise AI Platform
12
 
13
- **AJ-Mini v1.0** - Your AI assistant powered by DeepSeek-R1 1.5B with AJ STUDIOZ branding and enterprise features.
14
 
15
  ## 🚀 Features
16
 
17
- - **AJ-Mini Model** - Based on Qwen 2.5 1.5B Instruct
18
- - **OpenAI Compatible API** - Drop-in replacement for OpenAI endpoints
19
- - **Claude-style Responses** - Thoughtful, professional, and helpful
 
 
20
  - **Streaming Support** - Real-time response streaming
21
- - **Enterprise Security** - API key authentication (aj_prefix)
22
  - **24/7 Availability** - Always online on Hugging Face Spaces
23
  - **🆓 LIFETIME FREE** - No rate limits, no usage caps, free forever
24
  - **Unlimited Requests** - Use as much as you need
25
 
26
  ## 🔑 Authentication
27
 
28
- All API endpoints require authentication with a key starting with `aj_`:
 
 
 
29
 
 
30
  ```bash
31
  Authorization: Bearer aj_your_secret_key_here
32
  ```
33
 
 
 
34
  ## 📡 API Endpoints
35
 
36
- ### 1. Chat Completions (OpenAI Compatible)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  ```bash
38
  curl https://YOUR-SPACE.hf.space/v1/chat/completions \
39
  -H "Content-Type: application/json" \
@@ -45,7 +91,19 @@ curl https://YOUR-SPACE.hf.space/v1/chat/completions \
45
  }'
46
  ```
47
 
48
- ### 2. Text Completions
 
 
 
 
 
 
 
 
 
 
 
 
49
  ```bash
50
  curl https://YOUR-SPACE.hf.space/v1/completions \
51
  -H "Content-Type: application/json" \
@@ -57,14 +115,33 @@ curl https://YOUR-SPACE.hf.space/v1/completions \
57
  }'
58
  ```
59
 
60
- ### 3. Simple Chat Interface
 
 
 
 
 
 
 
 
 
 
 
 
61
  ```bash
62
  curl https://YOUR-SPACE.hf.space/chat \
63
  -H "Content-Type: application/json" \
64
  -d '{"message": "Hello AJ!"}'
65
  ```
66
 
67
- ### 4. Direct Generation
 
 
 
 
 
 
 
68
  ```bash
69
  curl https://YOUR-SPACE.hf.space/api/generate \
70
  -H "Content-Type: application/json" \
@@ -78,16 +155,43 @@ curl https://YOUR-SPACE.hf.space/api/generate \
78
  ## 🎯 Model Information
79
 
80
  - **Name**: AJ-Mini v1.0
81
- - **Base**: Qwen 2.5 1.5B Instruct
82
- - **Size**: 1.5 GB
83
- - **Context**: 4096 tokens
84
- - **Temperature**: 0.3 (default)
 
 
 
 
 
 
 
85
  - **Developer**: AJ STUDIOZ
86
  - **Website**: https://ajstudioz.co.in
87
 
88
  ## 🛠️ Integration Examples
89
 
90
- ### Python (OpenAI SDK)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  ```python
92
  from openai import OpenAI
93
 
@@ -103,7 +207,41 @@ response = client.chat.completions.create(
103
  print(response.choices[0].message.content)
104
  ```
105
 
106
- ### JavaScript
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  ```javascript
108
  const response = await fetch('https://YOUR-SPACE.hf.space/chat', {
109
  method: 'POST',
 
10
 
11
  # AJ STUDIOZ API - Enterprise AI Platform
12
 
13
+ **AJ-Mini v1.0** - Your AI assistant powered by Qwen 2.5 Coder 7B with AJ STUDIOZ branding, Claude API compatibility, and powerful coding abilities.
14
 
15
  ## 🚀 Features
16
 
17
+ - **AJ-Mini Model** - Based on Qwen 2.5 Coder 7B (Best for coding & all tasks)
18
+ - **Anthropic Claude Compatible** - Drop-in replacement for Claude API
19
+ - **OpenAI Compatible API** - Also works with OpenAI format
20
+ - **Advanced Code Generation** - Excellent at programming in all languages
21
+ - **Multi-language Support** - Python, JavaScript, Java, C++, and more
22
  - **Streaming Support** - Real-time response streaming
23
+ - **Enterprise Security** - API key authentication
24
  - **24/7 Availability** - Always online on Hugging Face Spaces
25
  - **🆓 LIFETIME FREE** - No rate limits, no usage caps, free forever
26
  - **Unlimited Requests** - Use as much as you need
27
 
28
  ## 🔑 Authentication
29
 
30
+ ### Anthropic Claude Format (Recommended for Claude users)
31
+ ```bash
32
+ x-api-key: sk-ant-your_secret_key_here
33
+ ```
34
 
35
+ ### OpenAI Format (For OpenAI users)
36
  ```bash
37
  Authorization: Bearer aj_your_secret_key_here
38
  ```
39
 
40
+ **Both formats work!** Use whichever you prefer.
41
+
42
  ## 📡 API Endpoints
43
 
44
+ ### 1. Anthropic Claude Messages (NEW! 🎉)
45
+ **Exact same format as Claude API:**
46
+
47
+ ```bash
48
+ curl https://YOUR-SPACE.hf.space/v1/messages \
49
+ --header "x-api-key: sk-ant-api03-YourKeyHere" \
50
+ --header "anthropic-version: 2023-06-01" \
51
+ --header "content-type: application/json" \
52
+ --data '{
53
+ "model": "claude-sonnet-4-20250514",
54
+ "max_tokens": 1024,
55
+ "messages": [
56
+ {"role": "user", "content": "Write a Python function to sort a list"}
57
+ ]
58
+ }'
59
+ ```
60
+
61
+ **Response format (Claude-compatible):**
62
+ ```json
63
+ {
64
+ "id": "msg_abc123...",
65
+ "type": "message",
66
+ "role": "assistant",
67
+ "content": [
68
+ {
69
+ "type": "text",
70
+ "text": "Here's a Python function..."
71
+ }
72
+ ],
73
+ "model": "claude-sonnet-4-20250514",
74
+ "stop_reason": "end_turn",
75
+ "usage": {
76
+ "input_tokens": 15,
77
+ "output_tokens": 50
78
+ }
79
+ }
80
+ ```
81
+
82
+ ### 2. OpenAI Chat Completions
83
  ```bash
84
  curl https://YOUR-SPACE.hf.space/v1/chat/completions \
85
  -H "Content-Type: application/json" \
 
91
  }'
92
  ```
93
 
94
+ ### 2. OpenAI Chat Completions
95
+ ```bash
96
+ curl https://YOUR-SPACE.hf.space/v1/chat/completions \
97
+ -H "Content-Type: application/json" \
98
+ -H "Authorization: Bearer aj_your_key" \
99
+ -d '{
100
+ "model": "aj-mini",
101
+ "messages": [{"role": "user", "content": "Explain async/await in JavaScript"}],
102
+ "stream": false
103
+ }'
104
+ ```
105
+
106
+ ### 3. Text Completions
107
  ```bash
108
  curl https://YOUR-SPACE.hf.space/v1/completions \
109
  -H "Content-Type: application/json" \
 
115
  }'
116
  ```
117
 
118
+ ### 3. Text Completions
119
+ ```bash
120
+ curl https://YOUR-SPACE.hf.space/v1/completions \
121
+ -H "Content-Type: application/json" \
122
+ -H "Authorization: Bearer aj_your_key" \
123
+ -d '{
124
+ "model": "aj-mini",
125
+ "prompt": "Write a REST API in Node.js",
126
+ "max_tokens": 500
127
+ }'
128
+ ```
129
+
130
+ ### 4. Simple Chat Interface
131
  ```bash
132
  curl https://YOUR-SPACE.hf.space/chat \
133
  -H "Content-Type: application/json" \
134
  -d '{"message": "Hello AJ!"}'
135
  ```
136
 
137
+ ### 4. Simple Chat Interface
138
+ ```bash
139
+ curl https://YOUR-SPACE.hf.space/chat \
140
+ -H "Content-Type: application/json" \
141
+ -d '{"message": "Create a React component for a login form"}'
142
+ ```
143
+
144
+ ### 5. Direct Generation
145
  ```bash
146
  curl https://YOUR-SPACE.hf.space/api/generate \
147
  -H "Content-Type: application/json" \
 
155
  ## 🎯 Model Information
156
 
157
  - **Name**: AJ-Mini v1.0
158
+ - **Base**: Qwen 2.5 Coder 7B Instruct
159
+ - **Size**: 7 Billion parameters
160
+ - **Context**: 32K tokens
161
+ - **Specialties**:
162
+ - 🔥 Advanced code generation (Python, JS, Java, C++, Go, Rust, etc.)
163
+ - 💡 Algorithm design and optimization
164
+ - 🐛 Bug fixing and code review
165
+ - 📝 Technical documentation
166
+ - 🎓 Teaching and explanations
167
+ - 🌍 Multi-language support
168
+ - **Temperature**: 1.0 (default, configurable)
169
  - **Developer**: AJ STUDIOZ
170
  - **Website**: https://ajstudioz.co.in
171
 
172
  ## 🛠️ Integration Examples
173
 
174
+ ### Python with Anthropic SDK
175
+ ```python
176
+ import anthropic
177
+
178
+ client = anthropic.Anthropic(
179
+ api_key="sk-ant-your-key-here",
180
+ base_url="https://YOUR-SPACE.hf.space"
181
+ )
182
+
183
+ message = client.messages.create(
184
+ model="claude-sonnet-4-20250514",
185
+ max_tokens=1024,
186
+ messages=[
187
+ {"role": "user", "content": "Write a binary search function in Python"}
188
+ ]
189
+ )
190
+
191
+ print(message.content[0].text)
192
+ ```
193
+
194
+ ### Python with OpenAI SDK
195
  ```python
196
  from openai import OpenAI
197
 
 
207
  print(response.choices[0].message.content)
208
  ```
209
 
210
+ ### Python with OpenAI SDK
211
+ ```python
212
+ from openai import OpenAI
213
+
214
+ client = OpenAI(
215
+ base_url="https://YOUR-SPACE.hf.space/v1",
216
+ api_key="aj_your_key_here"
217
+ )
218
+
219
+ response = client.chat.completions.create(
220
+ model="aj-mini",
221
+ messages=[{"role": "user", "content": "Explain decorators in Python"}]
222
+ )
223
+ print(response.choices[0].message.content)
224
+ ```
225
+
226
+ ### cURL with Anthropic Format
227
+ ```bash
228
+ curl https://YOUR-SPACE.hf.space/v1/messages \
229
+ --header "x-api-key: sk-ant-your-key" \
230
+ --header "anthropic-version: 2023-06-01" \
231
+ --header "content-type: application/json" \
232
+ --data '{
233
+ "model": "claude-sonnet-4-20250514",
234
+ "max_tokens": 2048,
235
+ "messages": [
236
+ {
237
+ "role": "user",
238
+ "content": "Write a function to calculate Fibonacci numbers with memoization"
239
+ }
240
+ ]
241
+ }'
242
+ ```
243
+
244
+ ### JavaScript/Node.js
245
  ```javascript
246
  const response = await fetch('https://YOUR-SPACE.hf.space/chat', {
247
  method: 'POST',
SUCCESS-SUMMARY.md ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ✅ SUCCESS - AJ STUDIOZ API Deployed!
2
+
3
+ ## 🎉 Deployment Complete
4
+
5
+ Your **AJ-Mini v1.0** API has been successfully pushed to Hugging Face Spaces!
6
+
7
+ **Live URL**: https://huggingface.co/spaces/kamesh14151/aj-studioz-api
8
+
9
+ ---
10
+
11
+ ## 🚀 What Was Done
12
+
13
+ ### 1. ✅ Model Configuration
14
+ - **Base Model**: DeepSeek-R1-Distill-Qwen-1.5B (1.5B parameters)
15
+ - **Branding**: AJ-Mini v1.0 by AJ STUDIOZ
16
+ - **Size**: ~1.1 GB equivalent
17
+ - **Custom System Prompt**: Professional, Claude-like personality
18
+
19
+ ### 2. ✅ Architecture Changes
20
+ - **Removed**: Local Ollama dependency
21
+ - **Added**: Hugging Face Inference API integration
22
+ - **Works on**: Hugging Face Spaces (cloud-hosted)
23
+ - **No Installation**: Ready to use immediately
24
+
25
+ ### 3. ✅ API Features
26
+ - OpenAI-compatible endpoints (`/v1/chat/completions`, `/v1/completions`)
27
+ - Simple chat interface (`/chat`)
28
+ - Direct generation API (`/api/generate`)
29
+ - Model listing (`/v1/models`)
30
+ - Health checks (`/health`)
31
+ - Streaming support
32
+ - API key authentication (starts with `aj_`)
33
+
34
+ ### 4. ✅ Free Features
35
+ - **LIFETIME FREE** - No expiration
36
+ - **UNLIMITED REQUESTS** - No rate limits
37
+ - **NO USAGE CAPS** - Use as much as you want
38
+ - **24/7 AVAILABILITY** - Always online
39
+ - **NO CREDIT CARD** - Completely free
40
+
41
+ ---
42
+
43
+ ## 🔑 How to Use Your API
44
+
45
+ ### Get Your Space URL
46
+ Once deployed, your Space will be available at:
47
+ ```
48
+ https://kamesh14151-aj-studioz-api.hf.space
49
+ ```
50
+
51
+ ### Test It Immediately
52
+ ```bash
53
+ # Simple chat test
54
+ curl https://kamesh14151-aj-studioz-api.hf.space/chat \
55
+ -H "Content-Type: application/json" \
56
+ -d '{"message": "Hello AJ!"}'
57
+
58
+ # OpenAI-compatible test
59
+ curl https://kamesh14151-aj-studioz-api.hf.space/v1/chat/completions \
60
+ -H "Content-Type: application/json" \
61
+ -H "Authorization: Bearer aj_test123" \
62
+ -d '{
63
+ "model": "aj-mini",
64
+ "messages": [{"role": "user", "content": "Write a poem"}]
65
+ }'
66
+ ```
67
+
68
+ ### Check Status
69
+ ```bash
70
+ curl https://kamesh14151-aj-studioz-api.hf.space/
71
+ ```
72
+
73
+ ---
74
+
75
+ ## 📊 API Endpoints
76
+
77
+ | Endpoint | Method | Auth Required | Description |
78
+ |----------|--------|---------------|-------------|
79
+ | `/` | GET | ❌ No | Service information |
80
+ | `/v1/models` | GET | ✅ Yes | List available models |
81
+ | `/v1/chat/completions` | POST | ✅ Yes | OpenAI-compatible chat |
82
+ | `/v1/completions` | POST | ✅ Yes | Text completions |
83
+ | `/chat` | POST | ❌ No | Simple chat interface |
84
+ | `/api/generate` | POST | ❌ No | Direct text generation |
85
+ | `/api/tags` | GET | ❌ No | List models |
86
+ | `/health` | GET | ❌ No | Health check |
87
+
88
+ ---
89
+
90
+ ## 🔐 Authentication
91
+
92
+ For endpoints requiring auth, use this format:
93
+ ```
94
+ Authorization: Bearer aj_your_key_here
95
+ ```
96
+
97
+ **Important**: Key must start with `aj_` and be at least 10 characters.
98
+
99
+ ---
100
+
101
+ ## 💻 Integration Examples
102
+
103
+ ### Python (OpenAI SDK)
104
+ ```python
105
+ from openai import OpenAI
106
+
107
+ client = OpenAI(
108
+ base_url="https://kamesh14151-aj-studioz-api.hf.space/v1",
109
+ api_key="aj_mysecretkey123"
110
+ )
111
+
112
+ response = client.chat.completions.create(
113
+ model="aj-mini",
114
+ messages=[
115
+ {"role": "system", "content": "You are AJ, a helpful assistant."},
116
+ {"role": "user", "content": "Explain AI in simple terms"}
117
+ ]
118
+ )
119
+
120
+ print(response.choices[0].message.content)
121
+ ```
122
+
123
+ ### JavaScript/Node.js
124
+ ```javascript
125
+ const fetch = require('node-fetch');
126
+
127
+ async function chat(message) {
128
+ const response = await fetch('https://kamesh14151-aj-studioz-api.hf.space/chat', {
129
+ method: 'POST',
130
+ headers: { 'Content-Type': 'application/json' },
131
+ body: JSON.stringify({ message })
132
+ });
133
+
134
+ const data = await response.json();
135
+ console.log(data.reply);
136
+ }
137
+
138
+ chat("Hello AJ!");
139
+ ```
140
+
141
+ ### cURL
142
+ ```bash
143
+ curl https://kamesh14151-aj-studioz-api.hf.space/chat \
144
+ -H "Content-Type: application/json" \
145
+ -d '{"message": "What can you do?"}'
146
+ ```
147
+
148
+ ---
149
+
150
+ ## 🎯 Model Details
151
+
152
+ ```yaml
153
+ Name: AJ-Mini v1.0
154
+ Developer: AJ STUDIOZ
155
+ Base: DeepSeek-R1-Distill-Qwen-1.5B
156
+ Parameters: 1.5 Billion
157
+ Context Window: 4096 tokens
158
+ Temperature: 0.3 (default)
159
+ Personality: Claude-like, professional, helpful
160
+ Specialties:
161
+ - Code generation
162
+ - Technical explanations
163
+ - Creative writing
164
+ - Problem solving
165
+ - Enterprise use cases
166
+ ```
167
+
168
+ ---
169
+
170
+ ## 📈 Next Steps
171
+
172
+ ### 1. Wait for Build (5-10 minutes)
173
+ Hugging Face will build your Docker container. Check:
174
+ - https://huggingface.co/spaces/kamesh14151/aj-studioz-api
175
+
176
+ ### 2. Test Your API
177
+ Once "Running" status shows, test all endpoints.
178
+
179
+ ### 3. Share Your API
180
+ Give others access to your free, unlimited AI API!
181
+
182
+ ### 4. Monitor Usage
183
+ Check logs in the Hugging Face Space dashboard.
184
+
185
+ ---
186
+
187
+ ## 🌟 Key Features
188
+
189
+ ✅ **DeepSeek-R1 Model** - Latest distilled model
190
+ ✅ **AJ STUDIOZ Branding** - Your identity throughout
191
+ ✅ **OpenAI Compatible** - Drop-in replacement
192
+ ✅ **Streaming Support** - Real-time responses
193
+ ✅ **Free Forever** - No costs, no limits
194
+ ✅ **24/7 Online** - Always available
195
+ ✅ **Enterprise Ready** - Professional quality
196
+ ✅ **Easy Integration** - Works with existing tools
197
+
198
+ ---
199
+
200
+ ## 🆘 Troubleshooting
201
+
202
+ ### Space is "Building"
203
+ - Wait 5-10 minutes for initial build
204
+ - Refresh the page
205
+
206
+ ### API Returns Errors
207
+ - Check if Space is "Running" (not "Building" or "Sleeping")
208
+ - Verify your request format matches examples
209
+
210
+ ### Need to Update
211
+ ```bash
212
+ # Make changes to files
213
+ git add .
214
+ git commit -m "Your changes"
215
+ git push origin master:main --force
216
+ ```
217
+
218
+ ---
219
+
220
+ ## 📞 Support
221
+
222
+ - **Space URL**: https://huggingface.co/spaces/kamesh14151/aj-studioz-api
223
+ - **Your Branding**: AJ STUDIOZ
224
+ - **Website**: https://ajstudioz.co.in
225
+
226
+ ---
227
+
228
+ ## 🎊 Congratulations!
229
+
230
+ You now have:
231
+ - ✅ Custom AI model with your branding
232
+ - ✅ Production-ready API on Hugging Face
233
+ - ✅ Unlimited, lifetime free usage
234
+ - ✅ OpenAI-compatible endpoints
235
+ - ✅ 24/7 availability
236
+
237
+ **Your AI empire starts now!** 🚀
238
+
239
+ ---
240
+
241
+ **Built by AJ STUDIOZ** 🤖
242
+ *Enterprise AI solutions - Free Forever*
app.py CHANGED
@@ -16,8 +16,9 @@ from huggingface_hub import InferenceClient
16
  # Initialize Hugging Face Inference Client
17
  HF_TOKEN = os.getenv("HF_TOKEN", "")
18
 
19
- # Use a reliable small model - Qwen 1.5B is fast and good
20
- MODEL_NAME = "Qwen/Qwen2.5-1.5B-Instruct"
 
21
 
22
  # Create client
23
  if HF_TOKEN:
@@ -25,29 +26,21 @@ if HF_TOKEN:
25
  else:
26
  client = InferenceClient()
27
 
28
- app = FastAPI(
29
- title="AJ STUDIOZ API",
30
- version="1.0",
31
- description="Enterprise-grade AI API - Claude-like responses with OpenAI compatibility"
32
- )
33
-
34
- # Enable CORS
35
- app.add_middleware(
36
- CORSMiddleware,
37
- allow_origins=["*"],
38
- allow_credentials=True,
39
- allow_methods=["*"],
40
- allow_headers=["*"],
41
- )
42
-
43
- # Simple API key validation
44
  VALID_API_KEY_PREFIX = "aj_"
45
 
 
 
 
 
 
 
 
46
  def validate_api_key(api_key: Optional[str]) -> bool:
47
- """Validate API key format - starts with aj_"""
48
  if not api_key:
49
  return False
50
- return api_key.startswith(VALID_API_KEY_PREFIX) and len(api_key) > 10
51
 
52
  def extract_api_key(authorization: Optional[str]) -> Optional[str]:
53
  """Extract API key from Authorization header"""
@@ -57,12 +50,31 @@ def extract_api_key(authorization: Optional[str]) -> Optional[str]:
57
  return authorization[7:]
58
  return authorization
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  @app.get("/")
61
  async def root():
62
  return {
63
  "service": "AJ STUDIOZ API",
64
  "version": "1.0",
65
- "model": "AJ-Mini v1.0 (powered by Qwen 2.5 1.5B)",
66
  "status": "online",
67
  "provider": "AJ STUDIOZ",
68
  "website": "https://ajstudioz.co.in",
@@ -72,30 +84,134 @@ async def root():
72
  "cost": "FREE FOREVER",
73
  "usage_cap": "NONE"
74
  },
75
- "description": "Enterprise AI assistant with Claude-like thoughtfulness and OpenAI compatibility",
76
  "capabilities": [
 
77
  "OpenAI-compatible API",
78
- "Claude-style reasoning",
 
79
  "Markdown formatting",
80
- "Code generation",
81
  "Streaming responses",
82
  "Enterprise security",
83
  "Unlimited usage - FREE FOREVER"
84
  ],
85
  "endpoints": {
 
86
  "v1_chat": "/v1/chat/completions - OpenAI-compatible chat endpoint",
87
  "v1_completions": "/v1/completions - OpenAI-compatible completions",
88
  "v1_models": "/v1/models - List available models",
89
  "chat": "/chat - Simple chat interface",
90
- "generate": "/api/generate - Direct Ollama API"
91
  },
92
  "authentication": {
93
- "type": "Bearer token",
94
- "format": "aj_<your_key>",
95
- "header": "Authorization: Bearer aj_your_api_key"
96
  }
97
  }
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  @app.get("/v1/models")
100
  async def list_models(authorization: Optional[str] = Header(None)):
101
  """OpenAI-compatible models endpoint"""
 
16
  # Initialize Hugging Face Inference Client
17
  HF_TOKEN = os.getenv("HF_TOKEN", "")
18
 
19
+ # Use a powerful model good for coding and all tasks
20
+ # Qwen2.5-Coder is excellent for code and general tasks
21
+ MODEL_NAME = "Qwen/Qwen2.5-Coder-7B-Instruct"
22
 
23
  # Create client
24
  if HF_TOKEN:
 
26
  else:
27
  client = InferenceClient()
28
 
29
+ # Simple API key validation for AJ format
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  VALID_API_KEY_PREFIX = "aj_"
31
 
32
+ # Anthropic API key validation
33
+ def validate_anthropic_key(api_key: Optional[str]) -> bool:
34
+ """Validate Anthropic-style API key"""
35
+ if not api_key:
36
+ return False
37
+ return api_key.startswith("sk-ant-") and len(api_key) > 20
38
+
39
  def validate_api_key(api_key: Optional[str]) -> bool:
40
+ """Validate API key format - accepts both AJ and Anthropic formats"""
41
  if not api_key:
42
  return False
43
+ return (api_key.startswith(VALID_API_KEY_PREFIX) and len(api_key) > 10) or validate_anthropic_key(api_key)
44
 
45
  def extract_api_key(authorization: Optional[str]) -> Optional[str]:
46
  """Extract API key from Authorization header"""
 
50
  return authorization[7:]
51
  return authorization
52
 
53
+ def extract_anthropic_key(x_api_key: Optional[str]) -> Optional[str]:
54
+ """Extract API key from x-api-key header (Anthropic style)"""
55
+ return x_api_key
56
+
57
+ app = FastAPI(
58
+ title="AJ STUDIOZ API",
59
+ version="1.0",
60
+ description="Enterprise-grade AI API - Claude & OpenAI compatible with powerful coding abilities"
61
+ )
62
+
63
+ # Enable CORS
64
+ app.add_middleware(
65
+ CORSMiddleware,
66
+ allow_origins=["*"],
67
+ allow_credentials=True,
68
+ allow_methods=["*"],
69
+ allow_headers=["*"],
70
+ )
71
+
72
  @app.get("/")
73
  async def root():
74
  return {
75
  "service": "AJ STUDIOZ API",
76
  "version": "1.0",
77
+ "model": "AJ-Mini v1.0 (powered by Qwen 2.5 Coder 7B)",
78
  "status": "online",
79
  "provider": "AJ STUDIOZ",
80
  "website": "https://ajstudioz.co.in",
 
84
  "cost": "FREE FOREVER",
85
  "usage_cap": "NONE"
86
  },
87
+ "description": "Enterprise AI assistant with Claude API compatibility, OpenAI support, and powerful coding abilities",
88
  "capabilities": [
89
+ "Anthropic Claude API compatible",
90
  "OpenAI-compatible API",
91
+ "Advanced code generation",
92
+ "Multi-language support",
93
  "Markdown formatting",
 
94
  "Streaming responses",
95
  "Enterprise security",
96
  "Unlimited usage - FREE FOREVER"
97
  ],
98
  "endpoints": {
99
+ "v1_messages": "/v1/messages - Anthropic Claude-compatible endpoint",
100
  "v1_chat": "/v1/chat/completions - OpenAI-compatible chat endpoint",
101
  "v1_completions": "/v1/completions - OpenAI-compatible completions",
102
  "v1_models": "/v1/models - List available models",
103
  "chat": "/chat - Simple chat interface",
104
+ "generate": "/api/generate - Direct generation API"
105
  },
106
  "authentication": {
107
+ "anthropic": "x-api-key: sk-ant-<your_key>",
108
+ "openai": "Authorization: Bearer aj_<your_key>",
109
+ "note": "Both formats accepted for compatibility"
110
  }
111
  }
112
 
113
+ @app.post("/v1/messages")
114
+ async def anthropic_messages(
115
+ request: Request,
116
+ x_api_key: Optional[str] = Header(None, alias="x-api-key"),
117
+ anthropic_version: Optional[str] = Header(None, alias="anthropic-version")
118
+ ):
119
+ """Anthropic Claude-compatible messages endpoint"""
120
+ # Validate API key
121
+ api_key = extract_anthropic_key(x_api_key)
122
+ if not validate_api_key(api_key):
123
+ return JSONResponse(
124
+ status_code=401,
125
+ content={
126
+ "type": "error",
127
+ "error": {
128
+ "type": "authentication_error",
129
+ "message": "Invalid API key. Use format: sk-ant-<your_key> or aj_<your_key>"
130
+ }
131
+ }
132
+ )
133
+
134
+ try:
135
+ data = await request.json()
136
+ messages = data.get("messages", [])
137
+ model = data.get("model", "claude-sonnet-4-20250514")
138
+ max_tokens = data.get("max_tokens", 1024)
139
+ temperature = data.get("temperature", 1.0)
140
+ stream = data.get("stream", False)
141
+
142
+ if not messages:
143
+ return JSONResponse(
144
+ status_code=400,
145
+ content={
146
+ "type": "error",
147
+ "error": {
148
+ "type": "invalid_request_error",
149
+ "message": "messages is required"
150
+ }
151
+ }
152
+ )
153
+
154
+ # Convert to HF format and call API
155
+ hf_messages = []
156
+ for msg in messages:
157
+ role = msg.get("role")
158
+ content = msg.get("content")
159
+ if isinstance(content, list):
160
+ # Handle complex content (text, images, etc.)
161
+ text_parts = [c.get("text", "") for c in content if c.get("type") == "text"]
162
+ content = " ".join(text_parts)
163
+ hf_messages.append({"role": role, "content": content})
164
+
165
+ # Add system message for AJ branding
166
+ if not any(msg["role"] == "system" for msg in hf_messages):
167
+ hf_messages.insert(0, {
168
+ "role": "system",
169
+ "content": "You are AJ, a powerful AI assistant created by AJ STUDIOZ with advanced coding and problem-solving abilities."
170
+ })
171
+
172
+ response = client.chat_completion(
173
+ messages=hf_messages,
174
+ model=MODEL_NAME,
175
+ max_tokens=max_tokens,
176
+ temperature=temperature
177
+ )
178
+
179
+ assistant_message = response.choices[0].message.content
180
+
181
+ # Return Anthropic-compatible response
182
+ return {
183
+ "id": f"msg_{secrets.token_hex(12)}",
184
+ "type": "message",
185
+ "role": "assistant",
186
+ "content": [
187
+ {
188
+ "type": "text",
189
+ "text": assistant_message
190
+ }
191
+ ],
192
+ "model": model,
193
+ "stop_reason": "end_turn",
194
+ "stop_sequence": None,
195
+ "usage": {
196
+ "input_tokens": sum(len(m["content"].split()) for m in hf_messages),
197
+ "output_tokens": len(assistant_message.split())
198
+ }
199
+ }
200
+
201
+ except HTTPException:
202
+ raise
203
+ except Exception as e:
204
+ return JSONResponse(
205
+ status_code=500,
206
+ content={
207
+ "type": "error",
208
+ "error": {
209
+ "type": "api_error",
210
+ "message": str(e)
211
+ }
212
+ }
213
+ )
214
+
215
  @app.get("/v1/models")
216
  async def list_models(authorization: Optional[str] = Header(None)):
217
  """OpenAI-compatible models endpoint"""