Media Generation
Generate Code
Generate production-quality code using the Theo Code engine.
POST
/
api
/
v1
/
code
Generate Code
curl --request POST \
--url https://api.example.com/api/v1/code \
--header 'Content-Type: application/json' \
--data '
{
"prompt": "<string>",
"language": "<string>",
"framework": "<string>"
}
'import requests
url = "https://api.example.com/api/v1/code"
payload = {
"prompt": "<string>",
"language": "<string>",
"framework": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({prompt: '<string>', language: '<string>', framework: '<string>'})
};
fetch('https://api.example.com/api/v1/code', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/code",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'prompt' => '<string>',
'language' => '<string>',
'framework' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/code"
payload := strings.NewReader("{\n \"prompt\": \"<string>\",\n \"language\": \"<string>\",\n \"framework\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/v1/code")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"<string>\",\n \"language\": \"<string>\",\n \"framework\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/code")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"<string>\",\n \"language\": \"<string>\",\n \"framework\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"created": "<string>",
"content": "<string>",
"artifacts": [
{}
],
"tools_used": [
{
"name": "<string>",
"status": "<string>"
}
],
"usage": {
"cost_cents": 123
}
}Generate code from a natural language prompt. The Theo Code engine is optimized for production-quality code and long-form output.
Authentication
Requires a Bearer token. See Authentication.Request Body
Description of the code to generate.
Target programming language (e.g.,
"typescript", "python", "go", "rust"). Appended as a hint to the engine.Target framework (e.g.,
"express", "nextjs", "fastapi", "gin"). Appended as a hint to the engine.Request Examples
curl -X POST https://www.hitheo.ai/api/v1/code \
-H "Authorization: Bearer $THEO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Write a TypeScript Express middleware for JWT authentication",
"language": "typescript",
"framework": "express"
}'
const res = await theo.code({
prompt: "Write a TypeScript Express middleware for JWT authentication",
language: "typescript",
framework: "express",
});
console.log(res.content); // Generated code
console.log(res.artifacts); // Any files created
Response
Unique code generation ID (prefixed
code_).ISO 8601 timestamp.
The generated code as text.
Any files created during generation (e.g., multi-file outputs).
Example Response
{
"id": "code_abc123",
"created": "2026-04-10T12:00:00Z",
"content": "import { Request, Response, NextFunction } from 'express';\nimport jwt from 'jsonwebtoken';\n\nexport function authMiddleware(req: Request, res: Response, next: NextFunction) {\n const token = req.headers.authorization?.split(' ')[1];\n if (!token) return res.status(401).json({ error: 'No token provided' });\n try {\n const decoded = jwt.verify(token, process.env.JWT_SECRET!);\n req.user = decoded;\n next();\n } catch {\n return res.status(401).json({ error: 'Invalid token' });\n }\n}",
"artifacts": [],
"tools_used": [],
"usage": { "cost_cents": 0.05 }
}
Errors
| Status | Code | Description |
|---|---|---|
| 400 | missing_prompt | prompt is required |
| 401 | invalid_api_key | Missing or invalid API key |
| 429 | rate_limit_exceeded | Too many requests |
Was this page helpful?
⌘I
Generate Code
curl --request POST \
--url https://api.example.com/api/v1/code \
--header 'Content-Type: application/json' \
--data '
{
"prompt": "<string>",
"language": "<string>",
"framework": "<string>"
}
'import requests
url = "https://api.example.com/api/v1/code"
payload = {
"prompt": "<string>",
"language": "<string>",
"framework": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({prompt: '<string>', language: '<string>', framework: '<string>'})
};
fetch('https://api.example.com/api/v1/code', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/code",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'prompt' => '<string>',
'language' => '<string>',
'framework' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/code"
payload := strings.NewReader("{\n \"prompt\": \"<string>\",\n \"language\": \"<string>\",\n \"framework\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/v1/code")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"<string>\",\n \"language\": \"<string>\",\n \"framework\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/code")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"<string>\",\n \"language\": \"<string>\",\n \"framework\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"created": "<string>",
"content": "<string>",
"artifacts": [
{}
],
"tools_used": [
{
"name": "<string>",
"status": "<string>"
}
],
"usage": {
"cost_cents": 123
}
}