Body Builder
Generate multiple parallel API requests from natural language
The Body Builder (linkora/bodybuilder) transforms natural language prompts into structured Linkora API requests, enabling you to easily run the same task across multiple models in parallel.
Overview
Body Builder uses AI to understand your intent and generate valid Linkora API request bodies. Simply describe what you want to accomplish and which models you want to use, and Body Builder returns ready-to-execute JSON requests.
Usage
The TypeScript SDK example imports Zod for runtime validation. Install it as a direct dependency alongside the SDK: npm install @linkora/sdk zod.
Body Builder currently accepts and returns Chat Completions request shapes, so these examples intentionally use /api/v1/chat/completions rather than the Responses API.
import { Linkora } from '@linkora/sdk';
import { z } from 'zod';
const LINKORA_API_KEY = '<LINKORA_API_KEY>';
const GeneratedMessageSchema = z.looseObject({
role: z.string(),
});
const BodyBuilderResponseSchema = z.object({
requests: z.array(
z.looseObject({
model: z.string(),
messages: z.array(GeneratedMessageSchema),
stream: z.literal(false).optional(),
}),
),
});
const ChatCompletionResponseSchema = z.looseObject({
choices: z
.array(
z.looseObject({
message: z.looseObject({ content: z.string() }),
}),
)
.min(1),
});
type BodyBuilderResponse = z.infer<typeof BodyBuilderResponseSchema>;
function parseBodyBuilderResponse(content: unknown): BodyBuilderResponse {
if (typeof content !== 'string') {
throw new Error('Expected Body Builder to return JSON text');
}
const parsed: unknown = JSON.parse(content);
return BodyBuilderResponseSchema.parse(parsed);
}
const linkora = new Linkora({
apiKey: LINKORA_API_KEY,
});
const completion = await linkora.chat.send({
chatRequest: {
model: 'linkora/bodybuilder',
messages: [
{
role: 'user',
content: 'Count to 10 using Claude Sonnet and GPT-5',
},
],
},
});
if (completion instanceof ReadableStream) {
throw new Error('Expected a non-streaming response');
}
// Parse the generated requests
const generatedRequests = parseBodyBuilderResponse(completion.choices[0]?.message.content);
console.log(generatedRequests);Response Format
Body Builder returns a JSON object containing an array of Linkora-compatible request bodies:
{
"requests": [
{
"model": "anthropic/claude-sonnet-4.5",
"messages": [
{"role": "user", "content": "Count to 10"}
]
},
{
"model": "openai/gpt-5.1",
"messages": [
{"role": "user", "content": "Count to 10"}
]
}
]
}Executing Generated Requests
After generating the request bodies, execute them in parallel:
// Generate the requests
const builderResponse = await linkora.chat.send({
chatRequest: {
model: 'linkora/bodybuilder',
messages: [{ role: 'user', content: 'Explain gravity using Gemini and Claude' }],
},
});
if (builderResponse instanceof ReadableStream) {
throw new Error('Expected a non-streaming response');
}
const { requests } = parseBodyBuilderResponse(builderResponse.choices[0]?.message.content);
// Body Builder returns API-format fields such as `max_tokens`, so send the
// generated JSON directly rather than converting it to SDK request types.
const results = await Promise.all(
requests.map(async (request) => {
const response = await fetch('https://link-ora.net/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${LINKORA_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(request),
});
if (!response.ok) {
await response.body?.cancel();
throw new Error(`Request failed with status ${response.status}`);
}
const data: unknown = await response.json();
const result = ChatCompletionResponseSchema.parse(data);
const choice = result.choices[0];
if (!choice) {
throw new Error('Expected at least one choice');
}
return { model: request.model, content: choice.message.content };
}),
);
// Process results
results.forEach(({ model, content }) => {
console.log(`Model: ${model}`);
console.log(`Response: ${content}\n`);
});Use Cases
Model Benchmarking
Compare how different models handle the same task:
"Write a haiku about programming using Claude Sonnet, GPT-5, and Gemini"Redundancy and Reliability
Get responses from multiple providers for critical applications:
"Answer 'What is 2+2?' using three different models for verification"A/B Testing
Test prompts across models to find the best fit:
"Summarize this article using the top 5 coding models: [article text]"Exploration
Discover which models excel at specific tasks:
"Generate a creative story opening using various creative writing models"Model Selection
Body Builder has access to all available Linkora models and will:
- Use the latest model versions by default
- Select appropriate models based on your description
- Understand model aliases and common names
Example model references that work:
- "Claude Sonnet" →
anthropic/claude-sonnet-4.5 - "Claude Opus" →
anthropic/claude-opus-4.5 - "GPT-5" →
openai/gpt-5.1 - "Gemini" →
google/gemini-3.1-pro-preview - "DeepSeek" →
deepseek/deepseek-v3.2
Pricing
- Body Builder requests: Free (no charge for generating request bodies)
- Executing generated requests: Standard model pricing applies
Limitations
- Requires
messagesformat input - Generated requests use minimal required fields by default
- System messages in your input are preserved and forwarded
Related
- Auto Router - Automatic single-model selection
- Model Fallbacks - Configure fallback models
- Structured Outputs - Get structured JSON responses
