Integrating Lama API with Python SDK
Developers often ask how to correctly configure an API client for unclosed text generation. This guide provides a step-by-step integration process, covering SDK settings and a tested checklist for verifying connectivity and response formats.

Understanding the API Structure
Before writing code, it is essential to understand the structure of the API you are integrating. Our API is a hosted, OpenAI-compatible chat-completions service. It serves one uncensored open-weight text model identified by the string uncensored. The base URL for all requests is https://api.lamaapikey.com/v1. This means you can use standard OpenAI-compatible libraries in Python, such as the official openai package, by simply pointing them to our base URL.
The API supports three main endpoints: POST /v1/chat/completions for generating text, POST /v1/responses for newer response formats, and GET /v1/models to verify available models. Unlike many competitors, we do not offer embeddings, image generation, audio processing, or video features. The focus is strictly on text input and text output.
This simplicity is a feature, not a limitation. By focusing on a single model, we ensure consistent performance and predictable pricing. The model does not refuse lawful adult, fictional, security-research, or controversial topics, making it suitable for developers building creative writing tools, role-playing bots, or research applications. However, it does enforce a hard content limit regarding sexual content involving minors, which will result in a refusal.
When integrating, remember that this is an independent service. It is not an official product of any major tech company. Therefore, you should not expect SLA guarantees, SOC2 certifications, or on-prem deployment options. The service is designed for developers who need reliable text generation without the overhead of managing infrastructure or dealing with complex model routing.
Setting Up Your Python Environment
To begin integration, you need a Python environment with the necessary libraries installed. The most common approach is to use the official OpenAI Python package, as our API is compatible with its protocol. You can install this package using pip. This allows you to use existing code snippets and documentation from the broader OpenAI ecosystem.
Once installed, you will need to configure the client with your API key and the base URL. You can obtain your key by signing up via Google or email. The key is shown immediately after signup, so you can use it right away. The key is tied to your account and has a limit of 300 requests per minute. If you exceed this limit, you will receive a 429 rate limit error.
It is important to note that our pricing is based on token usage, not request counts. The cost is $0.15 per 1 million input tokens and $0.50 per 1 million output tokens. You can start with a free trial of $0.50 credit, which requires no credit card. This allows you to test the integration thoroughly before committing to a payment.
Payments are accepted only via cryptocurrency. You can top up your account with USDT on the TRC20 network or USDC on the Base network. The minimum top-up amount is $20, and the maximum is $500. You can also receive bonus credit for top-ups of $50 or more. Credit never expires, and errors or refusals do not consume your balance.
Configuring the Client for Text Generation
With your environment set up, you can now configure the client to send requests. The primary endpoint for text generation is POST /v1/chat/completions. You need to pass the model ID uncensored and your messages in the standard format. Messages should include a role, such as system, user, or assistant, and the content of the message.
Our API supports several parameters to control the generation process. You can set the temperature to adjust creativity, use top_p for nucleus sampling, and define stop sequences to halt generation. You can also set a seed for reproducible results. These parameters allow you to fine-tune the output to match your specific use case, whether it is creative writing or technical analysis.
Streaming is supported via Server-Sent Events (SSE). This allows you to receive tokens as they are generated, which improves the user experience for applications that display text in real-time. The usage information, such as token counts, is included in the last chunk of the stream. This is useful for tracking costs and monitoring API usage.
Function calling, also known as tool calling, is another key feature. You can define tools in your request, and the model can return structured data to invoke these tools. This is essential for building agents that can interact with external systems or perform complex tasks. The JSON mode is also available for strict output formatting.
Handling Errors and Rate Limits
When integrating any API, error handling is important. Our API returns specific error codes to help you diagnose issues. A 401 error indicates an invalid API key, which means you should check your credentials. A 402 error means you have no credit left, and you will need to top up your account using crypto. A 429 error indicates that you have exceeded the rate limit of 300 requests per minute.
It is important to implement retry logic in your code to handle transient errors. However, be careful not to overwhelm the server with rapid retries. You should also handle the case where the model refuses a request due to the hard content limit on sexual content involving minors. This refusal is free, so it does not affect your credit balance.
Rate limits are per key, not per account. If you are using multiple keys, each key has its own limit of 300 requests per minute. This allows you to scale your application by distributing requests across multiple keys. However, you must manage these keys carefully to avoid hitting the limit on any single key.
Errors and refusals are free, which is a significant advantage for developers testing their applications. You can send many requests without worrying about costs until you start generating actual text. This makes it easy to iterate on your prompts and parameters without financial risk.
Verifying Connectivity and Response Formats
After setting up your client, you should verify connectivity by sending a simple test request. Use the free trial credit to send a message to the uncensored model. Check that you receive a valid response with the expected format. The response should include the generated text, the model ID, and usage statistics.
It is also important to verify that the streaming functionality works correctly. Send a request with streaming enabled and check that you receive tokens in real-time. Ensure that the last chunk contains the usage information. This is critical for applications that rely on real-time feedback.
You should also test the function calling feature if you plan to use it. Define a simple tool and send a request that triggers the tool. Check that the model returns the correct structured data. This ensures that your application can interact with external systems as expected.
Finally, test the error handling by sending a request with an invalid key or insufficient credit. Verify that you receive the correct error codes and messages. This helps you build a reliable application that can handle unexpected issues gracefully.
When Our API Is Not the Right Choice
While our API is excellent for text generation, it may not be the right choice for every project. If you need embeddings, image generation, audio processing, or video generation, our API does not support these features. You would need to use a different service for those capabilities.
Similarly, if you require fine-tuning of the model to customize its behavior for a specific domain, our API does not offer this feature. You would need to look for a provider that supports fine-tuning. Also, if you need on-prem deployment for data privacy reasons, our hosted service may not meet your requirements.
Additionally, if you need high availability with strict SLA guarantees, our service may not be suitable. We are an independent service and do not offer SLA percentages or certifications like SOC2 or HIPAA. For enterprise clients with strict compliance needs, this could be a limiting factor.
Finally, if you prefer to pay with credit cards or PayPal, our crypto-only payment method might be a barrier. You would need to acquire cryptocurrency to use our service. For developers who prefer traditional payment methods, this could be a drawback.
Best Practices for Integration
To ensure a smooth integration, follow these best practices. First, always use the latest version of the OpenAI Python package to benefit from the latest features and bug fixes. Second, implement proper error handling to manage rate limits and other errors gracefully.
Third, use streaming for better user experience, especially for long responses. This allows users to see the output in real-time, which can improve engagement. Fourth, monitor your usage to stay within your rate limits and budget. You can check your usage via the API responses.
Fifth, test your application thoroughly using the free trial credit before launching. This helps you identify any issues early and ensures that your application works as expected. Sixth, keep your API keys secure and rotate them regularly to prevent unauthorized access.
Finally, stay updated with our documentation for any changes to the API or pricing. Since we are an independent service, updates may occur without extensive notice. By following these best practices, you can build a reliable and efficient application using our API.
Frequently asked questions
How do I get an API key?
You can sign up via Google or email on our site. The key is shown immediately after signup, so you can use it right away without waiting for email confirmation.
What payment methods are accepted?
We only accept crypto payments. You can top up with USDT on the TRC20 network or USDC on the Base network. Credit cards and PayPal are not supported.
Is there a free trial?
Yes, every new account gets $0.50 of trial credit. No credit card is needed to start, allowing you to test the API thoroughly before paying.
What is the rate limit?
The rate limit is 300 requests per minute per key. If you exceed this limit, you will receive a 429 error. You can scale by using multiple keys.