Writon API Documentation

Welcome to the Writon API documentation. This API provides RESTful endpoints for AI-powered text processing, including grammar correction, translation, and summarization.

Base URL

http://localhost:8000

Authentication & BYOK (Bring Your Own Key)

Writon operates on a BYOK model. To use the API, you must provide your own API key for one of the supported providers in the request headers.

Required Headers for BYOK

Header Value Description
X-Provider groq | openai | google | anthropic The AI provider to use for processing.
X-{provider}-Key your_api_key The API key for the selected provider. Replace {provider} with the provider's name (e.g., X-Groq-Key).
X-{provider}-Model (Optional) model_name A specific model to use for the selected provider.

API Endpoints

GET /

Root endpoint providing basic API information.

Example Response

{
  "message": "\u2728 Writon API - AI-powered text processing",
  "version": "0.1.0",
  "docs": "/docs",
  "health": "/health"
}

GET /health

Health check endpoint to verify server status.

Example Response

{
  "status": "healthy",
  "version": "0.1.0",
  "provider": "groq",
  "timestamp": "2025-09-09T12:00:00.000000"
}

GET /providers

Returns a list of available providers and supported configurations.

Example Response

{
  "available_providers": [
    "openai",
    "google",
    "anthropic",
    "groq"
  ],
  "current_provider": "groq",
  "supported_modes": [
    "grammar",
    "translate",
    "summarize"
  ],
  "supported_cases": [
    "lower",
    "sentence",
    "title",
    "upper"
  ]
}

POST /upload

Uploads a text file (.txt, .md, .rtf) and returns its content.

Request Body

{
  "file": "file"
}

Example Request (cURL)

curl -X POST "http://localhost:8000/upload" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@/path/to/your/file.txt"

POST /grammar

Corrects grammar, spelling, and punctuation errors in a given text.

Request Body

{
  "text": "string (min: 1, max: 10000)",
  "case_style": "string (one of: lower, sentence, title, upper)"
}

Example Request (cURL)

curl -X POST "http://localhost:8000/grammar" \
  -H "Content-Type: application/json" \
  -H "X-Provider: groq" \
  -H "X-Groq-Key: your_groq_api_key_here" \
  -d '{
    "text": "this text has grammar mistake",
    "case_style": "sentence"
  }'

POST /translate

Translates a text to a specified target language.

Request Body

{
  "text": "string (min: 1, max: 10000)",
  "target_language": "string",
  "case_style": "string (one of: lower, sentence, title, upper)"
}

Example Request (cURL)

curl -X POST "http://localhost:8000/translate" \
  -H "Content-Type: application/json" \
  -H "X-Provider: google" \
  -H "X-Google-Key: your_google_api_key_here" \
  -d '{
    "text": "Hello, how are you?",
    "target_language": "Spanish",
    "case_style": "sentence"
  }'

POST /summarize

Condenses a long text into a concise summary.

Request Body

{
  "text": "string (min: 1, max: 10000)",
  "case_style": "string (one of: lower, sentence, title, upper)"
}

Example Request (cURL)

curl -X POST "http://localhost:8000/summarize" \
  -H "Content-Type: application/json" \
  -H "X-Provider: openai" \
  -H "X-OpenAI-Key: your_openai_api_key_here" \
  -d '{
    "text": "Your long text here...",
    "case_style": "title"
  }'

POST /process

A single endpoint to handle all processing modes. This is the endpoint the front-end uses.

Request Body

{
  "text": "string (min: 1, max: 10000)",
  "mode": "string (one of: grammar, translate, summarize)",
  "case_style": "string (one of: lower, sentence, title, upper)",
  "target_language": "string (Required for 'translate' mode)"
}

Example Request (cURL)

curl -X POST "http://localhost:8000/process" \
  -H "Content-Type: application/json" \
  -H "X-Provider: anthropic" \
  -H "X-Anthropic-Key: your_anthropic_api_key_here" \
  -d '{
    "text": "this text needs grammar fixing",
    "mode": "grammar",
    "case_style": "sentence"
  }'