likhonsheikh commited on
Commit
7989a2d
Β·
verified Β·
1 Parent(s): 8e2f1db

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +103 -5
README.md CHANGED
@@ -1,10 +1,108 @@
1
  ---
2
- title: Anthropic Compatible Api
3
- emoji: 🐨
4
- colorFrom: blue
5
- colorTo: green
6
  sdk: docker
7
  pinned: false
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Anthropic Compatible API
3
+ emoji: πŸ€–
4
+ colorFrom: purple
5
+ colorTo: blue
6
  sdk: docker
7
  pinned: false
8
+ license: apache-2.0
9
  ---
10
 
11
+ # Anthropic-Compatible API
12
+
13
+ A lightweight, CPU-based API endpoint that provides **Anthropic Messages API compatibility** using the SmolLM2-135M model.
14
+
15
+ ## Features
16
+
17
+ - βœ… Full Anthropic Messages API compatibility
18
+ - βœ… Streaming support (SSE)
19
+ - βœ… Token counting endpoint
20
+ - βœ… Ultra-lightweight (135M parameters)
21
+ - βœ… CPU-optimized
22
+ - βœ… No GPU required
23
+
24
+ ## API Endpoints
25
+
26
+ ### Create Message
27
+ ```bash
28
+ POST /v1/messages
29
+ ```
30
+
31
+ ### Example Request
32
+ ```bash
33
+ curl -X POST "https://YOUR_SPACE.hf.space/v1/messages" \
34
+ -H "Content-Type: application/json" \
35
+ -H "x-api-key: your-api-key" \
36
+ -H "anthropic-version: 2023-06-01" \
37
+ -d '{
38
+ "model": "smollm2-135m",
39
+ "max_tokens": 256,
40
+ "messages": [
41
+ {"role": "user", "content": "Hello, how are you?"}
42
+ ]
43
+ }'
44
+ ```
45
+
46
+ ### Streaming Example
47
+ ```bash
48
+ curl -X POST "https://YOUR_SPACE.hf.space/v1/messages" \
49
+ -H "Content-Type: application/json" \
50
+ -d '{
51
+ "model": "smollm2-135m",
52
+ "max_tokens": 256,
53
+ "stream": true,
54
+ "messages": [
55
+ {"role": "user", "content": "Tell me a short story"}
56
+ ]
57
+ }'
58
+ ```
59
+
60
+ ## SDK Compatibility
61
+
62
+ ### Python
63
+ ```python
64
+ import anthropic
65
+
66
+ client = anthropic.Anthropic(
67
+ api_key="any-key",
68
+ base_url="https://YOUR_SPACE.hf.space"
69
+ )
70
+
71
+ message = client.messages.create(
72
+ model="smollm2-135m",
73
+ max_tokens=256,
74
+ messages=[{"role": "user", "content": "Hello!"}]
75
+ )
76
+ print(message.content[0].text)
77
+ ```
78
+
79
+ ### TypeScript/JavaScript
80
+ ```typescript
81
+ import Anthropic from '@anthropic-ai/sdk';
82
+
83
+ const client = new Anthropic({
84
+ apiKey: 'any-key',
85
+ baseURL: 'https://YOUR_SPACE.hf.space'
86
+ });
87
+
88
+ const message = await client.messages.create({
89
+ model: 'smollm2-135m',
90
+ max_tokens: 256,
91
+ messages: [{ role: 'user', content: 'Hello!' }]
92
+ });
93
+ console.log(message.content[0].text);
94
+ ```
95
+
96
+ ## Model Info
97
+
98
+ - **Model**: HuggingFaceTB/SmolLM2-135M-Instruct
99
+ - **Parameters**: 135 Million
100
+ - **Optimized for**: CPU inference
101
+ - **Context Length**: 2048 tokens
102
+
103
+ ## Rate Limits
104
+
105
+ This is a free CPU-based endpoint. Please be mindful of usage.
106
+
107
+ ---
108
+ Built with ❀️ by Matrix Agent