๐ API is Live! Start making requests immediately โ no API key required.
๐ก Base URL
https://gpt-oss-2t-ai.hf.space/api
โก Quick Start
JavaScript (Fetch API)
const response = await fetch('https://gpt-oss-2t-ai.hf.space/api', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
messages: [{ role: 'user', content: 'Hello!' }],
stream: false,
temperature: 0.8
})
});
const data = await response.json();
console.log(data.choices[0].message.content);
Python
import requests
response = requests.post(
'https://gpt-oss-2t-ai.hf.space/api',
json={
'messages': [{'role': 'user', 'content': 'Hello!'}],
'stream': False,
'temperature': 0.8
}
)
data = response.json()
print(data['choices'][0]['message']['content'])
cURL
curl -X POST https://gpt-oss-2t-ai.hf.space/api \
-H "Content-Type: application/json" \
-d '{"messages":[{"role":"user","content":"Hello!"}],"stream":false}'
๐ Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
messages | array | โ Yes | Array of message objects |
stream | boolean | โ No | Enable streaming (default: true) |
temperature | number | โ No | Sampling temperature 0.0-2.0 (default: 0.8) |
max_tokens | number | โ No | Maximum tokens (default: -1) |
top_p | number | โ No | Nucleus sampling (default: 0.9) |
๐ Rate Limits
โ ๏ธ Per-IP Rate Limiting: Max 2 requests/second, 500ms minimum delay
๐ค AI Implementation Guide
How to integrate this AI API into your application:
Step 1: Make Your First Request
// Basic chat completion
const response = await fetch('https://gpt-oss-2t-ai.hf.space/api', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is AI?' }
],
stream: false,
temperature: 0.8
})
});
const data = await response.json();
console.log(data.choices[0].message.content);
Step 2: Enable Streaming (Real-time Responses)
// Streaming response for real-time text
const response = await fetch('https://gpt-oss-2t-ai.hf.space/api', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
messages: [{ role: 'user', content: 'Tell me a story' }],
stream: true
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
const lines = chunk.split('\\n').filter(line => line.trim());
for (const line of lines) {
if (line.startsWith('data: ')) {
const data = line.slice(6);
if (data === '[DONE]') continue;
const parsed = JSON.parse(data);
const content = parsed.choices?.[0]?.delta?.content || '';
process.stdout.write(content); // Display in real-time
}
}
}
Step 3: Build a Chat Interface
class AIChat {
constructor() {
this.apiUrl = 'https://gpt-oss-2t-ai.hf.space/api';
this.messages = [];
}
async sendMessage(userMessage) {
// Add user message to history
this.messages.push({ role: 'user', content: userMessage });
const response = await fetch(this.apiUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
messages: this.messages,
stream: false,
temperature: 0.8
})
});
const data = await response.json();
const aiResponse = data.choices[0].message.content;
// Add AI response to history
this.messages.push({ role: 'assistant', content: aiResponse });
return aiResponse;
}
// Clear chat history
reset() {
this.messages = [];
}
}
// Usage:
const chat = new AIChat();
const response = await chat.sendMessage('Hello!');
console.log(response);
Step 4: Advanced Configuration
// Fine-tune AI behavior with parameters
const response = await fetch('https://gpt-oss-2t-ai.hf.space/api', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
messages: [{ role: 'user', content: 'Write a poem' }],
temperature: 0.8, // Default: 0.8 (0.0-2.0)
max_tokens: -1, // Default: -1 (unlimited)
top_p: 0.9, // Default: 0.9 (0.0-1.0)
stream: false
})
});
Use Cases & Examples
| Use Case | Temperature | Example Prompt |
|---|---|---|
| ๐ฌ Chat Bot | 0.7-0.9 | Conversational responses |
| ๐ Content Writing | 0.8-1.2 | Creative and engaging content |
| ๐ป Code Generation | 0.2-0.5 | Accurate code snippets |
| ๐ Data Analysis | 0.1-0.3 | Precise analytical responses |
| ๐จ Creative Writing | 1.0-1.5 | Stories, poems, ideas |
๐งช Test the API
๐ ๏ธ Technical Details
Infrastructure:
- Fully server-side PHP application
- Automatic retry with exponential backoff (3 attempts)
- Per-IP rate limiting and request queuing
- Server-Sent Events (SSE) streaming
- System prompt auto-injection