API
Integrate models via API
Use the ModelStudio API to integrate your fine-tuned models into applications.
Authentication
ModelStudio uses bearer tokens for API authentication. These tokens are created within ModelStudio itself.
Creating API Keys
- Navigate to Organizational Settings → API Keys
- Click Create API Key
- Give it a descriptive name
- Copy and securely store the token
Security: API keys are shown only once. Store them securely and never commit them to version control.
Using API Keys
Include your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEYBase URL
https://api.modelstudio.appAPI Endpoints
Create Generation Job
POST /api/v1/organizations/<YOUR_ORGANIZATION_ID>/generate
Submit a generation job for processing.
Request Parameters:
{
"model_id": "your_model_id",
"messages": [[
{"role": "user", "content": "Your prompt here"}
]],
"temperature": 0.7,
"max_tokens": 512
}model_id(required): Your fine-tuned model IDmessages(required): Array of conversation arrays for batch processingtemperature(optional): 0.0-1.0, controls randomness, default 0.7max_tokens(optional): Maximum response length, default 512
Response:
{
"job_id": "job_abc123",
"status": "CREATED",
"message": "Generation job created successfully"
}Retrieve Generation Output
GET /api/v1/organizations/<YOUR_ORGANIZATION_ID>/generate/<JOB_ID>
Poll for job completion and retrieve results.
Response:
{
"job_id": "job_abc123",
"job_status": "completed",
"total_tasks": 1,
"completed_tasks": 1,
"results": [
{
"task_index": 0,
"status": "completed",
"result": "Generated text response",
"error": null
}
]
}Code Examples
Python
import requests
API_KEY = "your_api_key"
ORG_ID = "your_org_id"
MODEL_ID = "your_model_id"
# Create generation job
response = requests.post(
f"https://api.modelstudio.app/api/v1/organizations/{ORG_ID}/generate",
headers={"Authorization": f"Bearer {API_KEY}"},
json={
"model_id": MODEL_ID,
"messages": [[
{"role": "user", "content": "Hello, how are you?"}
]],
"temperature": 0.7,
"max_tokens": 512
}
)
job_id = response.json()["job_id"]
# Get results
result = requests.get(
f"https://api.modelstudio.app/api/v1/organizations/{ORG_ID}/generate/{job_id}",
headers={"Authorization": f"Bearer {API_KEY}"}
)
print(result.json())import requests
import time
API_KEY = "your_api_key"
ORG_ID = "your_org_id"
MODEL_ID = "your_model_id"
def generate_and_wait(messages, max_wait=60):
# Submit job
response = requests.post(
f"https://api.modelstudio.app/api/v1/organizations/{ORG_ID}/generate",
headers={"Authorization": f"Bearer {API_KEY}"},
json={
"model_id": MODEL_ID,
"messages": messages,
"temperature": 0.7,
"max_tokens": 512
}
)
job_id = response.json()["job_id"]
# Poll for completion
start_time = time.time()
while time.time() - start_time < max_wait:
result = requests.get(
f"https://api.modelstudio.app/api/v1/organizations/{ORG_ID}/generate/{job_id}",
headers={"Authorization": f"Bearer {API_KEY}"}
)
data = result.json()
if data["job_status"] == "completed":
return data["results"]
time.sleep(2)
raise TimeoutError("Job did not complete in time")
# Usage
messages = [[{"role": "user", "content": "Hello!"}]]
results = generate_and_wait(messages)
print(results[0]["result"])JavaScript
const API_KEY = "your_api_key";
const ORG_ID = "your_org_id";
const MODEL_ID = "your_model_id";
// Create generation job
const response = await fetch(
`https://api.modelstudio.app/api/v1/organizations/${ORG_ID}/generate`,
{
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
model_id: MODEL_ID,
messages: [[
{ role: "user", content: "Hello, how are you?" }
]],
temperature: 0.7,
max_tokens: 512
})
}
);
const { job_id } = await response.json();
// Poll for results
const pollResults = async (jobId, maxAttempts = 30) => {
for (let i = 0; i < maxAttempts; i++) {
const result = await fetch(
`https://api.modelstudio.app/api/v1/organizations/${ORG_ID}/generate/${jobId}`,
{ headers: { "Authorization": `Bearer ${API_KEY}` } }
);
const data = await result.json();
if (data.job_status === "completed") {
return data.results;
}
await new Promise(resolve => setTimeout(resolve, 2000));
}
throw new Error("Timeout");
};
const results = await pollResults(job_id);
console.log(results[0].result);cURL
# Create generation job
curl -X POST https://api.modelstudio.app/api/v1/organizations/<ORG_ID>/generate \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model_id": "your_model_id",
"messages": [[
{"role": "user", "content": "Hello!"}
]],
"temperature": 0.7,
"max_tokens": 512
}'
# Get results
curl https://api.modelstudio.app/api/v1/organizations/<ORG_ID>/generate/<JOB_ID> \
-H "Authorization: Bearer YOUR_API_KEY"Batch Processing
Process multiple inputs in a single API call:
{
"model_id": "your_model_id",
"messages": [
[{"role": "user", "content": "First input"}],
[{"role": "user", "content": "Second input"}],
[{"role": "user", "content": "Third input"}]
]
}Results are returned in the same order.
Multi-Turn Conversations
Include conversation history:
{
"model_id": "your_model_id",
"messages": [[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is AI?"},
{"role": "assistant", "content": "AI stands for..."},
{"role": "user", "content": "Tell me more"}
]]
}Vision Models
For vision models, include images as base64:
{
"model_id": "your_vision_model_id",
"messages": [[
{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{
"type": "image_url",
"image_url": {
"url": "data:image/jpeg;base64,/9j/4AAQSkZJRg..."
}
}
]
}
]]
}Error Handling
Common HTTP status codes:
| Code | Meaning |
|---|---|
| 401 | Invalid or missing API key |
| 403 | Insufficient permissions |
| 404 | Model or job not found |
| 400 | Invalid request format |
| 500 | Server error |
Code Generation in Web UI
ModelStudio provides ready-to-use code examples directly in the web interface:
- Navigate to the Models section
- Select your fine-tuned model
- Click the code icon
- Copy the generated code for your preferred language
Best Practices
Security
- Store API keys securely (environment variables, secrets management)
- Never expose keys in client-side code
- Rotate keys periodically
Performance
- Use batch processing for multiple inputs
- Implement exponential backoff for retries
- Monitor job completion times
Error Handling
- Implement retry logic
- Validate inputs before submission
- Log errors for debugging
Next Steps
- Test your model in the web interface first
- Start with small-scale API testing
- Monitor performance and errors
- Scale to production volumes
Support: For API issues or questions, contact manufactAI through the platform.