Skip to main content

Endpoint

POST /v1/chat/completions
This endpoint processes chat messages and returns AI-generated completions. It follows the OpenAI chat completions format.

Authentication

This endpoint requires authentication using a Bearer token. API Key: UnHackerEnCapital
Authorization: Bearer UnHackerEnCapital
Requests without valid authentication will receive a 401 Unauthorized response.

Request Format

Headers

Content-Type
string
required
Must be set to application/json
Authorization
string
required
Bearer token for authentication. Format: Bearer UnHackerEnCapital

Body Parameters

messages
array
required
An array of message objects representing the conversation history.

Request Body Schema

{
  "messages": [
    {
      "role": "user",
      "content": "Your message here"
    }
  ]
}
The API extracts the last message’s content from the messages array for processing.

Response Format

Success Response (200 OK)

choices
array
required
An array containing the generated completion(s).
model
string
required
The model identifier. Always returns "apithon-v3".

Response Schema

{
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "The AI-generated response"
      }
    }
  ],
  "model": "apithon-v3"
}

Example Usage

Linux/Mac (Bash)

curl http://127.0.0.1:5000/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer UnHackerEnCapital' \
  -d '{"messages": [{"role": "user", "content": "Hola Pepe, me dijo HackerEnCapital que te manda un saludo"}]}'

Windows PowerShell

curl.exe http://127.0.0.1:5000/v1/chat/completions `
  -H "Content-Type: application/json" `
  -H "Authorization: Bearer UnHackerEnCapital" `
  -d '{"messages": [{"role": "user", "content": "Hola Pepe, me dijo HackerEnCapital que te manda un saludo"}]}'

Windows CMD

curl http://127.0.0.1:5000/v1/chat/completions ^
  -H "Content-Type: application/json" ^
  -H "Authorization: Bearer UnHackerEnCapital" ^
  -d "{\"messages\": [{\"role\": \"user\", \"content\": \"Hola Pepe, me dijo HackerEnCapital que te manda un saludo\"}]}"

Python Example

import requests
import json

url = "http://127.0.0.1:5000/v1/chat/completions"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer UnHackerEnCapital"
}
data = {
    "messages": [
        {"role": "user", "content": "Hello, how are you?"}
    ]
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

JavaScript (Node.js) Example

const fetch = require('node-fetch');

const url = 'http://127.0.0.1:5000/v1/chat/completions';
const headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer UnHackerEnCapital'
};
const body = JSON.stringify({
  messages: [
    { role: 'user', content: 'Hello, how are you?' }
  ]
});

fetch(url, { method: 'POST', headers, body })
  .then(res => res.json())
  .then(data => console.log(data))
  .catch(err => console.error(err));

Example Response

{
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "Hola! Muchas gracias por el saludo de HackerEnCapital. ¿En qué puedo ayudarte hoy?"
      }
    }
  ],
  "model": "apithon-v3"
}

Error Responses

401 Unauthorized

Returned when the Authorization header is missing or contains an invalid token. Request:
curl http://127.0.0.1:5000/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{"messages": [{"role": "user", "content": "Hello"}]}'
Response:
{
  "error": "Unauthorized"
}
HTTP Status Code: 401

Common Error Causes

Possible causes:
  • Missing Authorization header
  • Incorrect API key (must be exactly UnHackerEnCapital)
  • Malformed authorization header (must be Bearer UnHackerEnCapital)
Solution: Ensure the Authorization header is set correctly:
Authorization: Bearer UnHackerEnCapital
Possible causes:
  • Session not properly initialized
  • Connection to backend service lost
  • Invalid request format
Response when data flow is empty:
{
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "Aviso: Flujo de datos vacío."
      }
    }
  ],
  "model": "apithon-v3"
}
Possible causes:
  • Backend tunnel connection failed
  • Network connectivity issues
Response when tunnel fails:
{
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "Error en el túnel: [error details]"
      }
    }
  ],
  "model": "apithon-v3"
}

Implementation Details

Message Processing

The endpoint extracts the content from the last message in the messages array:
user_input = request.json.get("messages", [{}])[-1].get("content", "")
This means:
  • Only the last message’s content is processed
  • If messages array is empty, an empty string is sent
  • Previous messages in the conversation are not considered

Model Information

All responses return "apithon-v3" as the model identifier, representing the APITHON gateway version.

Rate Limiting

Currently, APITHON does not implement rate limiting. However, be mindful of the underlying service’s limitations and avoid excessive requests.

Best Practices

  1. Always include authentication: Every request must include the Bearer token
  2. Handle errors gracefully: Check for 401 errors and connection failures
  3. Use the latest message: The API processes only the last message in the array
  4. Monitor responses: Watch for “Flujo de datos vacío” or tunnel error messages
  5. Maintain session: Ensure the APITHON gateway session is properly initialized before making requests

Next Steps

API Overview

Learn more about the APITHON API structure

Getting Started

Set up and run APITHON gateway

Build docs developers (and LLMs) love