EN ▾
Start now

Integrating Glmnsfw with Your Chat Application

Connecting an uncensored text API to a frontend chat interface requires careful attention to streaming and error handling. This guide walks you through the integration steps, SDK configuration, and a tested checklist to ensure your app sends and receives text correctly.

Laptop screen showing a chat interface with flowing text lines in a dark modern workspace.

Setting Up the Base Connection

Starting your integration begins with configuring the base URL and authentication. Our API uses a standard OpenAI-compatible endpoint structure, which means you can often reuse existing client libraries with minimal changes. The base URL for this service is https://api.glmnsfw.com/v1. You will need to set this in your client configuration along with your API key, which is displayed immediately after signup.

When initializing your client, ensure you specify the model ID as "uncensored". This tells the system to use the specific open-weight model designed for less restrictive outputs. Unlike other providers that might default to a different model, this service requires you to explicitly select this model ID to access the uncensored capabilities.

Authentication is handled via a simple API key passed in the header. You can generate this key by signing up with Google or using an email and password. The key is shown immediately upon creation, so make sure to copy it securely. If you lose the key, you may need to generate a new one, so keep it in a safe place.

It is important to note that this service does not offer embeddings, image generation, or fine-tuning. If your application requires those features, this API is not the right choice. However, for pure text generation, the setup is straightforward and follows familiar patterns used by many other large language model providers.

Configuring Parameters for Chat

Once the connection is established, you can configure the parameters that control how the model generates text. The API supports a range of standard parameters such as temperature, top_p, stop sequences, and seed. These allow you to fine-tune the creativity and determinism of the responses.

For example, setting a lower temperature will produce more consistent and predictable outputs, which is useful for factual or structured data. A higher temperature allows for more creative and varied responses, which is often preferred for fictional storytelling or brainstorming. You can also use the seed parameter to reproduce specific outputs for testing purposes.

The context window for this API is 100,000 tokens, covering both the prompt and the completion. This is a generous limit that allows for long conversations or detailed prompts without losing context. However, keep in mind that the context window is shared between input and output, so very long outputs will reduce the space available for subsequent turns.

JSON mode is also available if you need structured output. This can be useful for extracting data from the chat or for integrating with other systems that expect JSON-formatted responses. You can enable this mode by setting the appropriate parameter in your request.

Implementing Streaming Responses

Streaming is a critical feature for chat applications, as it allows users to see responses as they are generated rather than waiting for the entire response to complete. Our API supports streaming over Server-Sent Events (SSE), which is a standard protocol for this purpose.

When you enable streaming, the API sends chunks of text as they are generated. Your client should listen for these chunks and append them to the display area. This creates a more engaging user experience, especially for longer responses. The usage information, such as token counts, is included in the last chunk of the stream.

To implement streaming, you need to set the stream parameter to true in your request. The client will then receive a series of events, each containing a partial response. You should handle these events to update the UI in real-time. Make sure to handle the end of the stream properly to finalize the response.

Streaming also helps in managing latency, as users do not have to wait for the entire response to be generated before seeing any text. This is particularly important for applications where responsiveness is key, such as real-time chat or interactive storytelling.

Handling Errors and Rate Limits

Errors are an inevitable part of any API integration. Our API returns specific HTTP status codes to help you diagnose issues. A 401 error indicates an invalid or missing API key, while a 402 error means you have run out of credit. A 429 error signals that you have exceeded the rate limit of 300 requests per minute per key.

When you encounter a 402 error, you will need to top up your credit. The service accepts crypto payments only, specifically USDT on TRC20 or USDC on Base. You can top up with any whole amount between $20 and $500. There is no monthly fee or subscription, so you only pay for what you use.

Rate limits are enforced to ensure fair usage. If you exceed 300 requests per minute, you will receive a 429 error. You can handle this by implementing a retry mechanism with exponential backoff in your application. This helps to avoid overwhelming the API and ensures a smoother experience for your users.

It is also worth noting that errors and refusals are free. If a request fails or is refused due to content policy, you are not charged for those tokens. This can help you manage your budget more effectively, especially when testing new prompts or features.

Managing Credit and Pricing

Understanding the pricing model is essential for budgeting your API usage. The cost is $0.15 per 1 million input tokens and $0.50 per 1 million output tokens. Credit is charged based on real token usage, and prepaid credit never expires. This means you can use your credit whenever you need it without worrying about expiration dates.

To top up your credit, you can use crypto payments. The minimum top-up amount is $20, and the maximum is $500. You can also receive bonus credit when you top up $50 or more, with bonuses ranging from 5% to 15%. This can help you get more value for your money, especially if you plan to use the API extensively.

When estimating your costs, focus on token counts rather than dollar amounts. You can calculate the cost by dividing the number of tokens by 1,000,000 and multiplying by the per-million price. This method helps you understand the true cost of your usage without getting bogged down in complex calculations.

Keep in mind that the trial credit of $0.50 is available for new accounts, allowing you to test the API without any initial investment. This is a great way to verify your integration before committing to a larger top-up. You do not need to provide a card to receive the trial credit.

When This API Is Not the Right Choice

While this API is excellent for uncensored text generation, it may not be the right choice for all applications. If your app requires image, audio, or video generation, this service does not support those features. Similarly, if you need embeddings for semantic search or fine-tuning for custom model training, this API is not suitable.

Additionally, if you require an SLA guarantee or certifications like SOC2 or HIPAA, this service does not offer those. It is an independent service focused on providing uncensored text generation without the bells and whistles of larger platforms. If you need those features, you might want to consider other vendors.

The service also does not support model routing, meaning you cannot switch between different models dynamically. If your application requires the flexibility to choose from multiple models based on the task, this API might not meet your needs. However, for dedicated uncensored text generation, it is a strong option.

Finally, if you prefer traditional payment methods like credit cards or PayPal, this service might not be ideal. It accepts crypto only, specifically USDT on TRC20 or USDC on Base. If your users or your business model relies on traditional payment gateways, you may need to find a different solution.

Testing and Troubleshooting

Testing your integration is important to ensure everything works as expected. Start by using the trial credit to send a few test requests. This will help you verify that your client is correctly configured and that you can receive responses. You can also use the test endpoint to check your API key and permissions.

If you encounter issues, check the error codes mentioned earlier. A 401 error usually means your key is incorrect or missing. A 402 error indicates you need to top up your credit. A 429 error means you have hit the rate limit. Use these codes to diagnose and resolve problems quickly.

It is also helpful to test different parameters, such as temperature and top_p, to see how they affect the output. This will help you find the right balance for your application. You can also test streaming to ensure that the real-time updates are working correctly.

Finally, consider testing the API under different load conditions to see how it performs. This will help you identify any potential bottlenecks or issues with rate limits. By thoroughly testing your integration, you can ensure a smooth experience for your users.

Frequently asked questions

How do I get started with the API?

Sign up with Google or email to get an API key immediately. Use the trial credit to test the API without any initial investment. Set the base URL to https://api.glmnsfw.com/v1 and the model ID to "uncensored".

What payment methods are accepted?

The service accepts crypto payments only, specifically USDT on TRC20 or USDC on Base. You can top up with amounts between $20 and $500. There are no credit card or PayPal options available.

How is pricing calculated?

Pricing is based on token usage at $0.15 per 1 million input tokens and $0.50 per 1 million output tokens. Credit is charged in real-time and never expires. Errors and refusals are free.

What happens if I exceed the rate limit?

If you exceed 300 requests per minute, you will receive a 429 error. You should implement a retry mechanism with exponential backoff to handle this. The rate limit is per API key.