Complete reference for the TechStone AI Cloud REST API. Unified endpoints compatible with OpenAI API format.
${API_BASE_URL}All API requests require a Bearer token in the Authorization header. Generate your API key from the Console.
# 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.
/v1/chat/completionsCreate a chat completion
{
"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
}{
"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 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 -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
}'| Code | Name | Description |
|---|---|---|
| 200 | OK | Request was successful. |
| 400 | Bad Request | The request was malformed or missing required parameters. |
| 401 | Unauthorized | Invalid or missing API key. Check your Authorization header. |
| 403 | Forbidden | Your API key does not have permission for this operation. |
| 404 | Not Found | The requested resource (model, endpoint) does not exist. |
| 429 | Rate Limit Exceeded | Too many requests. Implement retry with exponential backoff. |
| 500 | Server Error | An internal error occurred. Please retry after a brief wait. |
| 503 | Service Unavailable | The service is temporarily overloaded. Try again later. |
{
"error": {
"type": "rate_limit_error",
"code": "rate_limit_exceeded",
"message": "You have exceeded your rate limit. Please retry after 60 seconds.",
"param": null
}
}| Plan | RPM | TPM | Concurrent |
|---|---|---|---|
| Pay As You Go | 60 | 150,000 | 5 |
| Pro | 500 | 2,000,000 | 50 |
| Enterprise | Custom | Custom | Custom |
RPM = Requests Per Minute, TPM = Tokens Per Minute. Headers X-RateLimit-Remaining and X-RateLimit-Reset are included in every response.
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).
# 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# 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 completesTechStone 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: 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: 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")