My AI
Free Trial
Hi,
My AI
Train New AI
Analytics
Billing
API Management
Log Out

API Documentation

Integrate SparkGPT AI models into your applications

Quick Start

Get started with SparkGPT API in minutes. Here's a simple example to make your first API call:

cURL
curl -X POST https://sparkgpt.ai/api/askoutside \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model_id": 1,
    "user": "Hello, how are you?"
  }'

Authentication

All API requests require authentication using an API key. Include your API key in the Authorization header of each request.

Keep your API key secure. Do not share it publicly or commit it to version control.
Header
Authorization: Bearer YOUR_API_KEY

Chat API

Send messages to your trained AI model and receive responses.

Endpoint

POST /api/askoutside

Request Parameters

Parameter Type Required Description
model_id integer Yes The ID of your trained AI model
user string Yes The user's message to send to the AI

Response

JSON
{
  "message": {
    "role": "assistant",
    "content": "Hello! I'm doing well, thank you for asking. How can I help you today?"
  }
}

docs.chat_stream_api

docs.chat_stream_desc

Endpoint

POST /api/askoutsideStream

Request Parameters

Parameter Type Required Description
model_id integer Yes The ID of your trained AI model
user string Yes The user's message to send to the AI
stream boolean Yes docs.stream_desc

Response

docs.stream_response_desc

SSE Stream
data: {"choices":[{"delta":{"content":"Hello"}}]}

data: {"choices":[{"delta":{"content":"! "}}]}

data: {"choices":[{"delta":{"content":"How "}}]}

data: {"choices":[{"delta":{"content":"can "}}]}

data: {"choices":[{"delta":{"content":"I "}}]}

data: {"choices":[{"delta":{"content":"help "}}]}

data: {"choices":[{"delta":{"content":"you?"}}]}

data: [DONE]

Code Examples

JavaScript
const API_KEY = 'YOUR_API_KEY';
const API_URL = 'https://sparkgpt.ai/api/askoutsideStream';

async function chatStream(modelId, message) {
  const response = await fetch(API_URL, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      model_id: modelId,
      user: message,
      stream: true
    })
  });
  
  const reader = response.body.getReader();
  const decoder = new TextDecoder();
  let buffer = '';
  
  while (true) {
    const {done, value} = await reader.read();
    if (done) break;
    
    buffer += decoder.decode(value, {stream: true});
    const lines = buffer.split('\\n');
    buffer = lines.pop();
    
    for (const line of lines) {
      if (line.startsWith('data: ')) {
        const data = line.slice(6);
        if (data === '[DONE]') continue;
        
        const json = JSON.parse(data);
        if (json.choices?.[0]?.delta?.content) {
          console.log(json.choices[0].delta.content);
        }
      }
    }
  }
}

// Example usage
chatStream(1, 'Hello, how are you?');

Model Training Data API

Retrieve training questions and answers for your AI model.

Endpoint

POST /api/getModelTrain

Request Parameters

Parameter Type Required Description
model_id integer Yes The ID of your trained AI model

Response

JSON
[
  {
    "id": 1,
    "model_id": 5,
    "question": "What is your favorite tea?",
    "answer": "I love green tea",
    "created_at": "2024-01-01 10:00:00"
  }
]

Code Examples

Python

Python
import requests

API_KEY = "YOUR_API_KEY"
API_URL = "https://sparkgpt.ai/api/askoutside"

def chat(model_id, message):
    headers = {
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json"
    }
    data = {
        "model_id": model_id,
        "user": message
    }
    response = requests.post(API_URL, headers=headers, json=data)
    return response.json()

# Example usage
result = chat(1, "Hello, how are you?")
print(result["message"]["content"])

JavaScript

JavaScript
const API_KEY = 'YOUR_API_KEY';
const API_URL = 'https://sparkgpt.ai/api/askoutside';

async function chat(modelId, message) {
  const response = await fetch(API_URL, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      model_id: modelId,
      user: message
    })
  });
  return response.json();
}

// Example usage
chat(1, 'Hello, how are you?')
  .then(result => console.log(result.message.content));

Error Handling

The API uses standard HTTP status codes to indicate success or failure of requests.

Status Code Description
401 Unauthorized - Invalid or missing API key
403 Forbidden - You don't have permission to access this resource
429 Too Many Requests - Rate limit exceeded
500 Internal Server Error - Something went wrong on our end

Rate Limiting

API requests are rate limited based on your subscription plan. Rate limit information is included in response headers.

If you exceed your rate limit, upgrade your plan for higher limits.
Header Description
X-RateLimit-Limit Maximum requests allowed per day
X-RateLimit-Remaining Remaining requests for today