EN ▾
Try with trial credit

Integrating Heretic Project LLM with Python SDK

This guide walks you through connecting your Python application to the Heretic Project API. We focus on configuring the client library to ensure maximum reliability for uncensored text generation. The process is straightforward, requiring only basic authentication and parameter adjustments.

Neon-lit server rack representing the Heretic Project API endpoint in a dark room.

Setting Up the Environment

Begin by installing the official Python client library. This package simplifies the interaction with the API by handling authentication and request formatting. You can install it using pip in your virtual environment. This ensures that your project dependencies are isolated and manageable.

Next, create a new Python file for your integration script. Import the necessary modules from the client library. You will need to import the main client class and any error handling utilities provided. This setup prepares your code to communicate with the API endpoints.

Obtain your API key from the dashboard after signing up. The key is displayed immediately upon registration. Store this key securely in your environment variables or a configuration file. Never hardcode the key directly into your source code to prevent accidental exposure.

Initialize the client instance with your API key. Set the base URL to the official endpoint. This configuration directs all requests to the correct server. Verify the connection by making a simple test request. This step confirms that your credentials are valid and the network path is open.

Configuring Uncensored Output Parameters

The core of the Heretic Project API lies in its uncensored model. To maximize the reliability of uncensored output, you must adjust specific parameters in your requests. The model does not refuse lawful adult, fictional, or controversial topics by default. However, fine-tuning these settings can help you get the most consistent results.

Set the temperature parameter to a higher value, such as 0.9 or 1.0. This increases the randomness of the model's choices, allowing for more creative and less filtered responses. Lower temperatures make the output more deterministic and conservative. Experiment with different values to find the sweet spot for your use case.

Adjust the top_p parameter to control the diversity of the output. A value of 0.9 or higher allows the model to consider a wider range of potential tokens. This can help in generating more nuanced and less repetitive text. Combine this with the temperature setting for optimal results.

Use the stop parameter to define custom stopping sequences. This prevents the model from running too long or generating unwanted content. You can specify multiple stop sequences to halt the generation at specific points. This is particularly useful for maintaining control over the output format.

Handling Streaming Responses

For real-time applications, streaming responses are essential. The API supports streaming over Server-Sent Events (SSE). This allows you to receive tokens as they are generated, providing a smoother user experience. Implement a stream handler in your Python code to process these events.

Set the stream parameter to True in your request. The client library will then yield chunks of text as they arrive. Each chunk contains the partial response, allowing you to display it incrementally. This is ideal for chat interfaces or live data feeds.

Parse the incoming SSE data to extract the text content. The last chunk usually contains the usage information, including token counts. Use this data to track your consumption and ensure you stay within your prepaid credit limits. Handle any connection errors gracefully to maintain stability.

Close the stream connection properly after the response is complete. This releases resources and prevents memory leaks. Ensure that your error handling covers network interruptions and API rate limits. This robustness is important for production environments.

Managing Tokens and Costs

Understanding token usage is important for managing your account. The API charges $0.15 per 1M input tokens and $0.50 per 1M output tokens. Errors and refusals are free, so you only pay for actual text generation. This model is cost-effective for high-volume applications.

Track the token counts returned in the usage statistics. The context window supports up to 100,000 tokens for both prompt and completion. Monitor your usage to avoid unexpected charges. You can check your balance and usage history in the dashboard.

Top-up your account using crypto. The API accepts USDT on TRC20 or USDC on Base. You can add any whole amount from $20 to $500. Bonus credit is available for larger top-ups, ranging from 5% to 15%. This flexibility allows you to scale your usage as needed.

Use the seed parameter to ensure reproducibility. Setting a fixed seed allows you to get the same output for the same input. This is useful for testing and debugging. It helps in isolating issues related to randomness in the model's responses.

Function Calling and JSON Mode

The API supports function calling, allowing you to integrate external tools and services. Define your functions in the request and let the model decide when to call them. This feature is powerful for building agents that can perform actions based on text input.

Enable JSON mode to force the model to output structured data. This is useful for parsing responses programmatically. Set the response_format parameter to JSON. The model will then output valid JSON objects that you can easily parse in Python.

Define your function schemas clearly in the request. Include the function name, description, and parameters. The model uses this information to generate appropriate function calls. Ensure that your function definitions are accurate and comprehensive.

Handle the function calls in your code by executing the defined functions. Pass the arguments provided by the model to your functions. Collect the results and feed them back into the conversation if needed. This loop enables complex interactions and automation.

When This API Is Not the Right Choice

While the Heretic Project API is excellent for text generation, it may not be the right choice for all use cases. If you need image, audio, or video generation, this API does not support those capabilities. It is strictly a text-in, text-out service.

Similarly, if you require embeddings, OCR, or fine-tuning, this API does not offer those features. The model is a single uncensored text model, so you cannot route to different models or perform multi-modal tasks. Check the vendor documentation for current prices and limits if you need those features.

If you need an SLA guarantee or certified compliance like SOC2 or HIPAA, this service does not provide those. It is an independent service without formal certifications. For enterprises requiring strict compliance, you may need to look elsewhere.

Also, consider the payment method. The API accepts only crypto, specifically USDT on TRC20 or USDC on Base. If you prefer credit cards or PayPal, this service may not be suitable. The prepaid credit model also means you must manage your balance actively.

Addressing Community Questions

Users on Reddit often discuss the behavior of uncensored models and their integration. Threads on r/LocalLLaMA and r/LocalLLM frequently mention the challenges of managing GGUF models versus using an API. People ask if the uncensored version truly differs from standard models in practice.

One common question is whether the uncensored model handles roleplay and complex toolsets better. The consensus is that it performs well for creative writing and less constrained conversations. However, for highly structured data extraction, standard models might still be preferable.

Another topic is the difference between text encoders and uncensored text models. Some users wonder if an uncensored encoder makes a difference. The general view is that it matters most for prompt refinement, not for the core encoding accuracy.

Finally, developers ask about the reliability of the API compared to local models. The API offers consistency and ease of use, but local models give you more control over the environment. Choose the API for scalability and the local model for privacy and customization.

Frequently asked questions

How do I handle errors in the Python SDK?

The SDK raises specific exceptions for different error codes. A 401 error indicates an invalid key, while a 402 error means you have no credit. A 429 error signals that you have hit the rate limit. Catch these exceptions in your code to handle them gracefully.

Can I use the API for real-time chat applications?

Yes, the API supports streaming over Server-Sent Events. This allows you to receive tokens as they are generated, providing a smooth user experience. You can implement this in Python by setting the stream parameter to True and processing the chunks as they arrive.

What is the context window size?

The context window is 100,000 tokens, which includes both the prompt and the completion. This allows for long conversations and large documents. Keep in mind that the total token count cannot exceed this limit.

How do I top up my account?

You can top up your account using crypto. The API accepts USDT on TRC20 or USDC on Base. You can add any whole amount from $20 to $500. Bonus credit is available for larger top-ups, ranging from 5% to 15%.