Getting Started with SUTRA
SUTRA is a family of large multi-lingual language models developed by TWO AI, offering powerful AI capabilities through a simple, OpenAI-compatible API. This guide helps developers quickly integrate SUTRA-V2 for conversational AI, multilingual tasks, and more, from prototyping to production.
Installation
Install the required SDKs for your preferred programming language:
pip install openai
npm install openai
npm install openai react
Getting Your API Key
Sign up to receive free SUTRA API KEY. All API requests require a SUTRA API key. Store your key securely as an environment variable:
export SUTRA_API_KEY="your_api_key_here"
If you are using Google Colab, you can:
- Click the 🔑 icon in the left sidebar.
- Add a secret named
SUTRA_API_KEY
.
API Reference
Base URL
SUTRA API uses an API format compatible with OpenAI. By modifying the configuration, you can also use the OpenAI SDK or softwares compatible with the OpenAI API.
https://api.two.ai/v2
Chat Completions Endpoint
Interact with SUTRA-V2 in a conversational format.
- Endpoint:
/chat/completions
- Method: POST
- Required Headers:
Authorization: Bearer <YOUR_SUTRA_API_KEY>
Content-Type: application/json
- Optional Headers (Streaming):
Accept: text/event-stream
Request Parameters
Parameter | Type | Required | Description |
---|---|---|---|
model | string | Yes | Model ID (e.g., sutra-v2 ) |
messages | array | Yes | Array of message objects with role and content |
max_tokens | integer | No | Maximum tokens to generate (default: 1024) |
temperature | number | No | Controls randomness (0-1, default: 0.7) |
stream | boolean | No | If true , responses are sent incrementally |
Invoke the Chat Completion API
Once you have obtained an API key, you can access the SUTRA API using the example scripts below.
This is a non-stream example—set the stream
parameter to true
to receive a streaming response.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("SUTRA_API_KEY", "YOUR_SUTRA_API_KEY"),
base_url="https://api.two.ai/v2"
)
response = client.chat.completions.create(
model="sutra-v2",
messages=[{"role": "user", "content": "Tell me about Mars exploration in three sentences."}],
max_tokens=1024,
temperature=0.7
)
print(response.choices[0].message.content)
import { OpenAI } from "openai";
async function main() {
const client = new OpenAI({
apiKey: process.env.SUTRA_API_KEY || "YOUR_SUTRA_API_KEY",
baseURL: "https://api.two.ai/v2",
});
const response = await client.chat.completions.create({
model: "sutra-v2",
messages: [
{
role: "user",
content: "Tell me about Mars exploration in three sentences.",
},
],
max_tokens: 1024,
temperature: 0.7,
});
console.log(response.choices[0].message.content);
}
main();
import React, { useState } from "react";
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_SUTRA_API_KEY",
baseURL: "https://api.two.ai/v2",
dangerouslyAllowBrowser: true, // Note: Use a backend proxy in production
});
function App() {
const [prompt, setPrompt] = useState("");
const [response, setResponse] = useState("");
const handleSubmit = async () => {
try {
const result = await client.chat.completions.create({
model: "sutra-v2",
messages: [
{
role: "user",
content:
prompt || "Tell me about Mars exploration in three sentences.",
},
],
max_tokens: 1024,
temperature: 0.7,
});
setResponse(result.choices[0].message.content);
} catch (error) {
setResponse(`Error: ${error.message}`);
}
};
return (
<div style={{ padding: "20px" }}>
<input
type="text"
value={prompt}
onChange={(e) => setPrompt(e.target.value)}
placeholder="Ask SUTRA-V2 about Mars exploration..."
/>
<button onClick={handleSubmit}>Submit</button>
<p>{response}</p>
</div>
);
}
export default App;
Streaming Responses
Enable real-time output by setting "stream": true
and including the Accept: text/event-stream
header.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("SUTRA_API_KEY", "YOUR_SUTRA_API_KEY"),
base_url="https://api.two.ai/v2"
)
stream = client.chat.completions.create(
model="sutra-v2",
messages=[{"role": "user", "content": "Write a short story in Hindi about space exploration."}],
max_tokens=1024,
temperature=0.7,
stream=True
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
import { OpenAI } from "openai";
async function streamSutra() {
const client = new OpenAI({
apiKey: process.env.SUTRA_API_KEY || "YOUR_SUTRA_API_KEY",
baseURL: "https://api.two.ai/v2",
});
const stream = await client.chat.completions.create({
model: "sutra-v2",
messages: [
{
role: "user",
content: "Write a short story in Hindi about space exploration.",
},
],
max_tokens: 1024,
temperature: 0.7,
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || "");
}
}
streamSutra();
curl -X POST "https://api.two.ai/v2/chat/completions" \
-H "Authorization: Bearer $SUTRA_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{
"model": "sutra-v2",
"messages": [{"role": "user", "content": "मंगल ग्रह के अन्वेषण के बारे में एक छोटी कहानी लिखें।"}],
"max_tokens": 1024,
"temperature": 0.7,
"stream": true
}'
Multilingual Capabilities
SUTRA-V2 supports over 50 languages, including Hindi, Bengali, Gujarati, Tamil, Telugu, Japanese, Korean, English, French, German, and more. Simply provide input in any supported language, and SUTRA will respond accordingly.
Example in Hindi
response = client.chat.completions.create(
model="sutra-v2",
messages=[{"role": "user", "content": "भारत के अंतरिक्ष कार्यक्रम के बारे में तीन वाक्यों में बताएं।"}],
max_tokens=1024,
temperature=0.7
)
print(response.choices[0].message.content)
SUTRA Starter Guide Tutorial
Watch our comprehensive tutorial to quickly get started with SUTRA:
Troubleshooting
- Invalid API Key: Verify at TWO AI SUTRA API.
- Model Not Found: Use
sutra-v2
for conversations orsutra-r0
for reasoning. SUTRA-V1 was deprecated on March 22, 2025. - Rate Limits: Reduce request frequency.
- Language Issues: Ensure prompts align with the target language’s script and syntax.
Support
- Email: support@two.ai
- Documentation: https://docs.two.ai
- Visit Discord to get started.
Start building with SUTRA to create scalable, multilingual AI applications today!