How to Use Fabble API in Python: Complete Developer Tutorial
How to Use Fabble API in Python
If you want to use an AI model inside a Python application, an API is usually the most practical way to do it. Instead of manually opening an AI chat interface, your application can send a prompt to a model, receive the response and use that response as part of a larger workflow.
This guide explains how to use the Fabble API with Python. We will start with a basic API request and then build toward more practical patterns such as reusable functions, structured prompts, error handling and usage tracking.
The examples use an OpenAI-compatible API approach. This makes the integration familiar if you have already worked with the OpenAI Python SDK.
What Is the Fabble API?
An AI API provides a way for software to communicate with an AI model programmatically.
Instead of typing a question into a chat application, your Python program sends a request containing instructions and other relevant context. The API processes the request and returns a response that your application can use.
A typical workflow looks like this:
Python Application
↓
API Request
↓
AI Gateway
↓
Fabble Model
↓
API Response
↓
Python Application
This architecture can be used for chatbots, content tools, developer utilities, document processing systems and many other applications.
Why Use Fabble Through an API?
The main benefit of an API is automation.
You can make your application call the model whenever a particular event happens.
For example, a Python application could:
- Generate an answer to a user's question
- Summarize a document
- Extract information from text
- Generate application content
- Explain programming code
- Classify incoming text
- Build an AI-powered support system
- Process large numbers of requests automatically
The model becomes a component of your software instead of a separate application.
What You Need Before Starting
For this tutorial, you need:
- Python installed on your computer
- An API key
- Access to the Fabble model through your API provider
- The current Fabble model ID shown by the provider
If you are using Velona, you can use its OpenAI-compatible API endpoint to access supported models through a familiar API structure.
Create a Python Project
Start by creating a project directory:
mkdir fabble-python
cd fabble-python
It is a good idea to use a virtual environment:
python -m venv .venv
On Linux or macOS, activate it with:
source .venv/bin/activate
On Windows:
.venv\Scripts\activate
Now install the required packages:
pip install openai python-dotenv
Store Your API Key
API keys should not be hardcoded into your application.
Create a file called .env:
VELONA_API_KEY=your_api_key_here
VELONA_BASE_URL=https://velona.in/v1
Add the .env file to your .gitignore file:
.env
This prevents the key from accidentally being committed to a public Git repository.
Connect Python to the API
The OpenAI Python SDK can be used with an OpenAI-compatible API by specifying the appropriate base URL.
import os
from dotenv import load_dotenv
from openai import OpenAI
load_dotenv()
client = OpenAI(
api_key=os.environ["VELONA_API_KEY"],
base_url=os.environ["VELONA_BASE_URL"]
)
The client object can now be used to send requests to the API.
Find the Correct Fabble Model ID
One important detail when working with AI APIs is the model ID.
The human-readable model name and the identifier used in an API request are not always identical. Providers can also change model identifiers as new versions are introduced.
For that reason, use the current model catalog provided by your API provider and copy the model ID shown there.
Your request will follow this general structure:
response = client.chat.completions.create(
model="YOUR_FABBLE_MODEL_ID",
messages=[
{
"role": "user",
"content": "Explain how Python dictionaries work."
}
]
)
print(response.choices[0].message.content)
Replace YOUR_FABBLE_MODEL_ID with the current Fabble model identifier available in your account.
Send Your First Fabble Request
Once the client is configured, you can send a normal chat completion request.
response = client.chat.completions.create(
model="YOUR_FABBLE_MODEL_ID",
messages=[
{
"role": "user",
"content": "What are the main uses of Python in AI development?"
}
]
)
answer = response.choices[0].message.content
print(answer)
The important parts of the request are the model identifier and the messages array.
The response contains the generated message, which you can then display, store or process further in your application.
Understanding the Messages Structure
Chat APIs generally represent a conversation using messages with different roles.
A simple request can contain a user message:
messages=[
{
"role": "user",
"content": "Explain recursion in Python."
}
]
You can also provide system-level instructions when the API and selected model support them:
messages=[
{
"role": "system",
"content": "You are a concise Python programming assistant."
},
{
"role": "user",
"content": "Explain recursion with a simple example."
}
]
The system instruction establishes the general behavior while the user message contains the current task.
Write Better Prompts
The quality of the prompt has a major effect on the usefulness of the response.
Instead of:
Write Python code.
Give the model a clear objective:
Write a Python function called calculate_average.
Requirements:
- Accept a list of numbers
- Return the average
- Handle an empty list safely
- Include type hints
- Explain the implementation briefly
This gives the model more information about what the application actually needs.
Use Fabble for Code Generation
One practical use case is generating small pieces of code from a natural-language description.
prompt = """
Create a Python function that validates an email address.
Requirements:
- Accept an email string
- Return True or False
- Reject strings without an @ symbol
- Keep the implementation simple
- Explain the code after the function
"""
response = client.chat.completions.create(
model="YOUR_FABBLE_MODEL_ID",
messages=[
{"role": "user", "content": prompt}
]
)
print(response.choices[0].message.content)
This pattern can be used to create coding assistants and internal developer tools.
Use Fabble for Text Summarization
AI APIs are also useful when your application needs to process text automatically.
document = """
Artificial intelligence is being integrated into software products
across many industries. Developers are using language models for
search, summarization, automation, customer support and software
development.
"""
prompt = f"""
Summarize the following document in three bullet points.
Document:
{document}
"""
response = client.chat.completions.create(
model="YOUR_FABBLE_MODEL_ID",
messages=[
{"role": "user", "content": prompt}
]
)
print(response.choices[0].message.content)
Your application could use the same pattern for articles, support tickets, reports, notes or other text-based data.
Create a Reusable Fabble Function
Once you have tested a basic request, move the API logic into a reusable function.
def ask_fabble(prompt):
response = client.chat.completions.create(
model="YOUR_FABBLE_MODEL_ID",
messages=[
{
"role": "user",
"content": prompt
}
]
)
return response.choices[0].message.content
answer = ask_fabble(
"Explain Python list comprehensions with two examples."
)
print(answer)
Now other parts of your application can call ask_fabble() without knowing how the API request works internally.
Add System Instructions
For applications that need consistent behavior, system instructions can be useful.
response = client.chat.completions.create(
model="YOUR_FABBLE_MODEL_ID",
messages=[
{
"role": "system",
"content": """
You are a technical assistant.
Give practical answers.
Use Python examples when appropriate.
Keep explanations clear and concise.
"""
},
{
"role": "user",
"content": "How does a Python virtual environment work?"
}
]
)
print(response.choices[0].message.content)
This is more useful than repeating the same instruction in every individual prompt.
Handle API Errors
Network failures, authentication problems, invalid model IDs and insufficient account credits can all cause API requests to fail.
Your application should handle these situations instead of crashing.
try:
response = client.chat.completions.create(
model="YOUR_FABBLE_MODEL_ID",
messages=[
{
"role": "user",
"content": "Explain Python decorators."
}
]
)
print(response.choices[0].message.content)
except Exception as error:
print("The API request failed.")
print(error)
For production applications, use more specific exception handling and proper application logging rather than displaying raw errors to users.
Track API Usage
AI APIs are usage-based services, so monitoring consumption becomes important as your application grows.
Many chat completion responses expose usage information:
response = client.chat.completions.create(
model="YOUR_FABBLE_MODEL_ID",
messages=[
{
"role": "user",
"content": "Explain Python classes."
}
]
)
print(response.usage)
Usage information can help you understand how much input and output your application is generating.
This becomes especially important when processing long documents, running automated workflows or serving many users.
Build a Simple Fabble CLI App
We can combine the previous concepts into a small command-line application.
import os
from dotenv import load_dotenv
from openai import OpenAI
load_dotenv()
client = OpenAI(
api_key=os.environ["VELONA_API_KEY"],
base_url=os.environ["VELONA_BASE_URL"]
)
MODEL = "YOUR_FABBLE_MODEL_ID"
while True:
question = input("\nYou: ")
if question.lower() in ["exit", "quit"]:
break
try:
response = client.chat.completions.create(
model=MODEL,
messages=[
{
"role": "user",
"content": question
}
]
)
print("\nFabble:", response.choices[0].message.content)
except Exception as error:
print("\nRequest failed:", error)
Run it with:
python main.py
You now have a basic terminal-based AI application.
Keep Your API Key Secure
Your API key should stay on the server side whenever possible.
Do not put a production API key directly inside frontend JavaScript.
A safer architecture is:
Web Application
↓
Your Backend
↓
API Key
↓
AI Gateway
↓
Fabble
Your backend can authenticate users, validate requests, control usage and make the API call without exposing the secret key.
Common Fabble API Problems
Model Not Found
If you receive a model-not-found error, check the current model catalog and make sure you are using the exact model ID supported by your provider.
Authentication Failed
Check that your API key exists, is valid and is being loaded correctly from the environment.
Insufficient Balance
If your API provider uses prepaid billing, make sure your account has enough available credits for the request.
Request Too Large
Very large prompts can consume substantial context. If you are processing long documents, consider splitting them into relevant sections instead of sending everything in one request.
Unexpected Output
If the response does not follow your desired format, make the instructions more explicit. Tell the model what the output should contain and what it should avoid.
Using Fabble in a Real Application
The simple examples above are useful for learning, but production applications usually need another layer around the API.
A typical application might look like this:
User
↓
Frontend
↓
Python Backend
↓
Prompt Builder
↓
Fabble API
↓
Response Validation
↓
Application
↓
User
The backend can decide what information should be sent to the model, construct the prompt, validate the response and record usage.
This architecture also makes it easier to change models later without rewriting the entire application.
What Can You Build With the Fabble API?
Once you understand the basic API workflow, the same foundation can be used for many different applications.
- AI chat applications
- Writing assistants
- Document summarization tools
- Customer support systems
- Developer assistants
- Internal knowledge tools
- Text classification systems
- Content generation workflows
- Research assistants
The important idea is that the API is not the application itself. It is the connection between your software and the AI model.
Final Thoughts
Using Fabble through an API allows Python developers to integrate AI directly into their applications. The basic process is straightforward: create an API key, configure the Python client, select the current Fabble model ID, send a structured request and process the response.
Once the basic integration works, you can build reusable functions, better prompts, error handling, usage tracking and backend workflows around it.
If you are developing from India, an INR-based AI API platform can also make the operational side easier by providing a common API layer and rupee-based billing for supported models.
Start with a single request, make sure the response is what your application needs and then gradually add the engineering features required for production.