Server-to-server API
Integrate quiz and RAG
Add grounded quiz generation and retrieval-augmented answers to your backend using one Edy API key. This guide covers the customer setup, request contracts, and production integration rules.
Before you start
- 1. Create an Edy account and generate a key at Dashboard - API keys.
- 2. Ask an Edy administrator to provision the key for QUIZ and RAG routes.
- 3. Store the key in your backend secret manager as
EDY_API_KEY.
Never put the key in browser JavaScript, a mobile app, source control, or a public frontend environment variable.
Authentication
Use the deployment URL as the base URL and send the key as a Bearer token. The alternative X-API-Key header is also accepted.
const baseUrl = "https://edycode.vercel.app";
const headers = {
Authorization: `Bearer ${process.env.EDY_API_KEY}`,
"Content-Type": "application/json",
};Generate a quiz
Send extracted document text. Edy does not upload or extract files for this endpoint.
const response = await fetch(`https://edycode.vercel.app/api/v1/quiz/generate`, {
method: "POST",
headers,
body: JSON.stringify({
document_text: documentText,
question_count: 5,
question_types: ["multiple_choice", "true_false", "short_answer"],
difficulty: "medium",
}),
});
if (!response.ok) throw new Error(JSON.stringify(await response.json()));
const quiz = await response.json();Supported counts are 5 and 10. Supported types are multiple_choice, true_false, and short_answer. The returned questions include validated answers and explanations.
Add RAG answers
Your application owns document storage and retrieval. Build this pipeline in your backend:
- Extract text from the source document.
- Split it into chunks and assign stable IDs.
- Generate embeddings and store them in your vector database.
- Retrieve the best chunks for each query.
- Send those chunks to Edy as trusted context data.
const response = await fetch(`https://edycode.vercel.app/api/v1/rag/answer`, {
method: "POST",
headers,
body: JSON.stringify({
query: "What causes osmosis?",
context_chunks: [
{
chunk_id: "biology-001-chunk-03",
text: "Water moves from higher water potential to lower water potential during osmosis.",
retrieval_score: 0.91,
},
],
conversation_history: [],
stream: false,
}),
});
const answer = await response.json();
// answer.citations contains only submitted chunk IDs.Edy answers only from the supplied chunks. When the context is insufficient, the response has refused: true, an empty citations array, and low confidence.
Stream RAG responses
Set stream to true and parse Server-Sent Events on your server. Render answer.delta events as they arrive, but treat the completion event as the authoritative final result.
event: answer.delta
data: {"delta":"Osmosis occurs...","request_id":"..."}
event: completion
data: {"answer":"Osmosis occurs...","citations":["biology-001-chunk-03"],"confidence":"high","refused":false}Handle errors
| Status | Meaning |
|---|---|
401 | Missing, invalid, or revoked API key. |
403 | The key has not been provisioned for inference. |
413 | The document or RAG context exceeds its configured token limit. |
429 | A request, token, concurrency, or daily allowance was exceeded. Honor Retry-After. |
502-504 | Provider failure, malformed output, or timeout. Retry with backoff and log X-Request-Id. |
Production checklist
- Keep all Edy requests behind your backend.
- Log the Edy
X-Request-Idwith your own request ID. - Do not persist full document text or retrieved chunks in application logs.
- Use stable chunk IDs so citations can link back to your source document.
- Enforce your own tenant authorization before sending context to Edy.