I have prepared a small web api console app in aspenetcore asking on the port 5000
We need to add 3
Here u add an “ AI” icon https://icons8.it/icon/EzmQwT9W9uy4/chatgpt u can choose mod the proper
one u think will be better, the tooltip name is “Ai Generate”
User needs to select a text in the news in bodyxml
When u press it show a confirm message and a texts need to be select then u call the api then u
swap the old text with new one
Add a button “translate” https://icons8.it/icon/YIjgRIh1AXXI/translate u can choose mod the proper
one u think will be better, the tooltip name is “Ai Translate” , u need to show a list of this language :
Italian, English, French, Chinese, Spanish, Hindi, Arabic, Bengali, Portuguese, Russian, Japanese,
Punjabi, German, Javanese, Korean, Turkish, Vietnamese, Thai, Urdu, Persian
When u press it show a confirm message and a texts need to be select then u call the api then u
swap the old text with new one
--------------------------------------------------------------------------------------------------------------------------------
Add a button “translate” https://icons8.it/icon/lIiqyOBhTR5H/brave-ai u can choose mod the
proper one u think will be better, the tooltip name is “Ai Summarize ,”
When u press it show a confirm message and a texts need to be select then u call the api then u
swap the old text with new one
------------------------------------------------------------------------------------------------------------------------
Base URL
bash
CopiaModifica
http://localhost:{PORT}/api/process
PORT 5000 by default
HTTP Method
POST /api/process
Content-Type: application/json
Request Body
{
"command": "translate" | "regenerate" | "summaryze", // required*
"targetLanguage": "fr", // only for translate
"text": "string" // required
}
Field Type Required Notes
Accepted values:
• translate (alias typo tranlslate)
command string Yes*
• regenerate (default if omitted)
• summaryze (alias summarize)
Only meaningful when command = translate; any [ISO-639-
targetLanguage string No
1] code or language name.
Raw text to process. Max size depends on the model context
text string Yes
window.
*If you omit command the service behaves as if command = "regenerate".
Response
Success — HTTP 200
{
"result": "string"
}
The result string contains the model’s answer (translation, rewritten text, or summary).
Client Error — HTTP 400
text is required – empty or missing text.
Other JSON-binding errors will be returned as plain text in the body.
Behaviour per Command
Command Prompt Template internally used Language of result
“Translate the following text to targetLanguage (or source language if
translate
{targetLanguage} …” missing)
“Rewrite the following text with different
regenerate Same language as input text
words …”
summaryze “Summarize the following text …” Same language as input text
Example Requests
PowerShell (Invoke-RestMethod)
# Translate "Hello world" to French
$body = @{ command = "translate"; targetLanguage = "fr"; text = "Hello world" }
| ConvertTo-Json
Invoke-RestMethod http://localhost:5000/api/process -Method Post -Body $body -
ContentType "application/json"
cURL
curl -X POST http://localhost:5000/api/process \
-H "Content-Type: application/json" \
-d '{"command":"summaryze","text":"Long article here..."}'
C# (HttpClient)
var client = new HttpClient { BaseAddress = new Uri("http://localhost:5000") };
var payload = new
{
command = "regenerate",
text = "Natural-gas prices climbed 15 % yesterday…"
};
string json = JsonSerializer.Serialize(payload);
using var content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage resp = await client.PostAsync("/api/process", content);
resp.EnsureSuccessStatusCode();
string body = await resp.Content.ReadAsStringAsync();
string result =
JsonDocument.Parse(body).RootElement.GetProperty("result").GetString();
Console.WriteLine(result);
Environment & Configuration
Setting Where Purpose
OpenAI:ApiKey appsettings.json (Alternative) hard-code the key in config
OPENAI_API_KEY (env var) OS environment Preferred: keeps secrets out of source
Port appsettings.json Public port for Kestrel web server
Model hard-coded (gpt-4.1-nano) Change directly in code if needed
Re-editing appsettings.json while the app is running automatically reloads the port and key
(thanks to reloadOnChange: true).
Error-Handling Hints
400 → check JSON structure / required fields.
401/403 → invalid or missing OpenAI API key.
5xx → model failure or server-side exception (consult application console).