REST API v1

API Documentation

Complete reference for the TechStone AI Cloud REST API. Unified endpoints compatible with OpenAI API format.

Base URL

${API_BASE_URL}

Authentication

All API requests require a Bearer token in the Authorization header. Generate your API key from the Console.

bash
# Set your API base URL
export API_BASE_URL="<your-api-base-url>"

# Include your API key in every request
curl ${API_BASE_URL}/v1/chat/completions \
  -H "Authorization: Bearer $TECHSTONE_API_KEY" \
  -H "Content-Type: application/json"

Keep your API key secure

Never expose your API key in client-side code. Use environment variables and server-side proxies. All API calls must be made over HTTPS.

Endpoints

POST/v1/chat/completions

Create a chat completion

Request Body

json
{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "What is the Token economy?"
    }
  ],
  "temperature": 0.7,
  "max_tokens": 1024,
  "top_p": 1,
  "stream": false
}

Response (200 OK)

json
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1719000000,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The Token economy is a unified system..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 150,
    "total_tokens": 175
  }
}

Streaming Response

SSE
# Streaming request - set "stream": true
# Response is sent as Server-Sent Events:

data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"delta":{"content":"The"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"delta":{"content":" Token"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc","object":"chat.completion.chunk","choices":[{"delta":{"content":" economy"},"finish_reason":null}]}

data: [DONE]

cURL Example

bash
curl -X POST ${API_BASE_URL}/v1/chat/completions \
  -H "Authorization: Bearer $TECHSTONE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "What is the Token economy?"
    }
  ],
  "temperature": 0.7,
  "max_tokens": 1024,
  "top_p": 1,
  "stream": false
}'

Error Codes

CodeNameDescription
200OKRequest was successful.
400Bad RequestThe request was malformed or missing required parameters.
401UnauthorizedInvalid or missing API key. Check your Authorization header.
403ForbiddenYour API key does not have permission for this operation.
404Not FoundThe requested resource (model, endpoint) does not exist.
429Rate Limit ExceededToo many requests. Implement retry with exponential backoff.
500Server ErrorAn internal error occurred. Please retry after a brief wait.
503Service UnavailableThe service is temporarily overloaded. Try again later.

Error Response Format

json
{
  "error": {
    "type": "rate_limit_error",
    "code": "rate_limit_exceeded",
    "message": "You have exceeded your rate limit. Please retry after 60 seconds.",
    "param": null
  }
}

Rate Limits

PlanRPMTPMConcurrent
Pay As You Go60150,0005
Pro5002,000,00050
EnterpriseCustomCustomCustom

RPM = Requests Per Minute, TPM = Tokens Per Minute. Headers X-RateLimit-Remaining and X-RateLimit-Reset are included in every response.

Streaming Guide

Streaming allows you to receive partial results in real-time as the model generates them. Set "stream": true in your request to enable streaming. The response will be delivered as Server-Sent Events (SSE).

Python
# Streaming with Python SDK
from techstoneai import TechStoneAI

client = TechStoneAI(api_key="your-api-key")

stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write a poem about AI"}],
    stream=True
)

for chunk in stream:
    content = chunk.choices[0].delta.content
    if content:
        print(content, end="", flush=True)
print()  # Newline after streaming completes
Node.js
# Streaming with Node.js SDK
import TechStoneAI from '@techstoneai/sdk';

const client = new TechStoneAI({ apiKey: 'your-api-key' });

const stream = await client.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'Write a poem about AI' }],
  stream: true,
});

for await (const chunk of stream) {
  const content = chunk.choices[0]?.delta?.content || '';
  process.stdout.write(content);
}
console.log(); // Newline after streaming completes

OpenAI API Compatibility

TechStone AI Cloud is fully compatible with the OpenAI API format. If you are already using the OpenAI SDK, simply change the base URL to start using TechStone:

Python
# Python: Switch from OpenAI to TechStone
from techstoneai import TechStoneAI  # Drop-in replacement!
import os

# Just change the client initialization
client = TechStoneAI(
    api_key=os.environ.get("TECHSTONE_API_KEY"),
    base_url=os.environ.get("API_BASE_URL")  # Set in your environment
)

# Everything else works exactly the same
response = client.chat.completions.create(
    model="gpt-4o",  # Same model names
    messages=[{"role": "user", "content": "Hello!"}]
)
Node.js
# Node.js: Switch from OpenAI to TechStone
import TechStoneAI from '@techstoneai/sdk';

const client = new TechStoneAI({
  apiKey: process.env.TECHSTONE_API_KEY,
  baseURL: process.env.API_BASE_URL,  // Set in your environment
});

// Everything else works exactly the same
const response = await client.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'Hello!' }],
});

Tip: If you use the OpenAI SDK directly, configure the base URL via environment variable:

base_url=os.environ.get("API_BASE_URL")