Oracle
ORACLE
docs

Renamer API

The Oracle Renamer API provides an intelligent service for renaming variables and functions in Lua scripts. This guide explains how to use the API effectively.

Authentication

All API requests require authentication using an API key. Include your API key in the request headers:

ApiKey: YOUR_API_KEY

Endpoint

POST http://renamer.mshq.dev/api/rename

Request Format

The API accepts POST requests with a JSON body containing the following parameters:

ParameterTypeDescription
codestringThe Lua script content to be renamed
hashstringSHA-256 hash of the original file
filenamestringOriginal filename

Response Format

The API returns a JSON response with the following fields:

FieldTypeDescription
outputCodestringThe renamed Lua script
totalTokensnumberTotal tokens used for the operation

Response Codes

Status CodeDescription
200Success - Returns renamed code and token usage
400Bad Request - Invalid input format
401Unauthorized - Invalid API key
429Too Many Requests - Rate limit exceeded
500Server Error - Renaming failed

Example Usage (Node.js)

const fs = require('fs').promises;
const crypto = require('crypto');
const axios = require('axios');

async function renameScript(filePath) {
  try {
    // Read the script file
    const code = await fs.readFile(filePath, 'utf8');
    
    // Calculate SHA-256 hash
    const hash = crypto
      .createHash('sha256')
      .update(code)
      .digest('hex');

    // Make API request
    const response = await axios.post('https://oracle.mshq.dev/api/rename', {
      code,
      hash,
      filename: filePath.split('/').pop()
    }, {
      headers: {
        'Content-Type': 'application/json',
        'ApiKey': 'YOUR_API_KEY'
      }
    });

    // Handle successful response
    const { outputCode, totalTokens } = response.data;
    console.log(`Renaming completed using ${totalTokens} tokens`);
    
    // Save renamed code
    await fs.writeFile(`${filePath}.renamed.lua`, outputCode);
    console.log('Renamed code saved successfully');

  } catch (error) {
    if (error.response) {
      // Handle API error response
      console.error('API Error:', error.response.status, error.response.data);
    } else {
      // Handle network or other errors
      console.error('Error:', error.message);
    }
  }
}

Rate Limits

The API has the following rate limits:

  • Maximum of 10 scripts per minute per API key
  • Requests exceeding this limit will receive a 429 status code

For unlimited rate limits and better pricing, consider upgrading to Enterprise

Error Handling

When handling errors, your code should:

  • Check for rate limiting (429) and implement appropriate retry logic
  • Validate input parameters before making the API request
  • Handle network errors and API error responses appropriately
  • Log errors with sufficient detail for debugging