curl -X POST https://www.draftify.site/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_DRAFTIFY_API_KEY" \
-d '{
"model": "sonnet-4.6-level",
"stream": true,
"messages": [
{
"role": "user",
"content": "Write a long story about a robot."
}
]
}'
### Node.js Example
const response = await fetch('https://www.draftify.site/api/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.DRAFTIFY_API_KEY}`,
},
body: JSON.stringify({
model: 'sonnet-4.6-level',
stream: true,
messages: [{ role: 'user', content: 'Write a long story about a robot.' }]
}),
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value, { stream: true });
console.log(chunk);
}
──────
## Understanding the Stream Format
When streaming is enabled, the API will respond with a continuous stream of text chunks. Each event begins with data: and
contains a stringified JSON object.
A typical stream chunk looks like this:
data: {"choices": [{"index": 0, "delta": {"content": "Hello"}}]}
The very last event in the stream will always be:
data: [DONE]
──────
## Vercel AI SDK Integration
Because the Draftify API strictly follows the standard OpenAI Chat Completions format, it works out-of-the-box with popular
frameworks like the Vercel AI SDK.
You can use the @ai-sdk/openai provider and just override the baseURL to point to Draftify:
import { createOpenAI } from '@ai-sdk/openai';
import { streamText } from 'ai';
const draftify = createOpenAI({
baseURL: 'https://www.draftify.site/api/v1',
apiKey: process.env.DRAFTIFY_API_KEY,
});
export async function POST(req) {
const { messages } = await req.json();
const result = await streamText({
model: draftify('opus-4.8-level'),
messages,
});
return result.toDataStreamResponse();
}