๐Ÿค– GPT-OSS 2T API

Free, rate-limited AI API powered by GPT-OSS 2T

โœจ Model: gpt-oss:latest ๐Ÿš€ Fully Server-Side PHP ๐Ÿ”’ Rate Limited
๐ŸŽ‰ 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

ParameterTypeRequiredDescription
messagesarrayโœ… YesArray of message objects
streambooleanโŒ NoEnable streaming (default: true)
temperaturenumberโŒ NoSampling temperature 0.0-2.0 (default: 0.8)
max_tokensnumberโŒ NoMaximum tokens (default: -1)
top_pnumberโŒ NoNucleus 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 CaseTemperatureExample Prompt
๐Ÿ’ฌ Chat Bot0.7-0.9Conversational responses
๐Ÿ“ Content Writing0.8-1.2Creative and engaging content
๐Ÿ’ป Code Generation0.2-0.5Accurate code snippets
๐Ÿ“Š Data Analysis0.1-0.3Precise analytical responses
๐ŸŽจ Creative Writing1.0-1.5Stories, poems, ideas

๐Ÿงช Test the API

Health Check: GET https://gpt-oss-2t-ai.hf.space/api

Interactive Test: Test Page

๐Ÿ› ๏ธ 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