How to build an AI agent: step by step, no-code or in Python, with GPT, Claude and DeepSeek
An AI agent is a model that has been given tools and allowed to decide for itself which one to call: search a database, send an email, query an API. You can build one without programming — in n8n, Dify, Langflow or Flowise — or in Python in about 40 lines. Either way you need a key to a model that can call tools. With RuAPI one key opens GPT, Claude, DeepSeek and Gemini: from Russia with no VPN, paying in USDT only for the tokens you use.
Updated:
import json
from openai import OpenAI
client = OpenAI(base_url="https://www.ruapi.ai/v1", api_key="sk-...")
def get_weather(city):
return f"It is +5 °C in {city} right now" # your own code goes here
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Weather in a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
messages = [{"role": "user", "content": "What is the weather in Kazan?"}]
for _ in range(5): # no more than 5 steps
reply = client.chat.completions.create(
model="deepseek-flash", messages=messages, tools=tools
).choices[0].message
messages.append(reply)
if not reply.tool_calls: # the model answered in text — done
print(reply.content)
break
for call in reply.tool_calls: # the model asks to call a tool
args = json.loads(call.function.arguments)
messages.append({
"role": "tool",
"tool_call_id": call.id,
"content": get_weather(**args),
})
else:
print("Step limit reached")
A minimal agent in Python: the deepseek-flash model decides for itself whether to call the get_weather function, gets the result and answers. Replace the function with your own — a database search, a CRM query, sending a message. You need the openai package (pip install openai); replace sk-… with your RuAPI key. The same code works with gpt-6-luna and claude-sonnet-5-5 — only the model name changes.
What an AI agent is made of, and where people usually get stuck
An agent is a model, tools and a loop.
A chatbot answers with text. An agent gets a description of tools (functions), and at each step the model either answers or asks for a tool to be called with certain arguments. The program runs the call and returns the result to the model — and so on in a loop until the task is done. Builders like n8n hide this loop behind the AI Agent node, and in code it takes a few lines.
You need a model that can call tools.
Function calling (tool calling) is supported by GPT, Claude, DeepSeek, Gemini and Qwen. But OpenAI and Anthropic do not serve Russia, and their APIs cannot be paid for with a Russian bank card. RuAPI accepts requests in the OpenAI format at https://www.ruapi.ai/v1 — a format that n8n, Dify, Langflow, Flowise, LangChain and the OpenAI SDK all understand.
An agent spends more than a chat.
An agent makes several requests per task and each time sends the model the whole history and the tool descriptions. So three things matter: an inexpensive model for routine steps, a cap on the number of steps and a spending limit. In RuAPI the budget is set right on the key — the agent will not spend more than that amount.
How to build an AI agent: 5 steps
Steps 1–2 and 5 are common to both; at steps 3 and 4 pick one path — no-code or Python.
Describe the task and the tools
- State one task: “answer customers from a knowledge base”, “sort requests from email and enter them into a spreadsheet”, “find products by a query”.
- List what the agent needs to be able to do: read a spreadsheet, search documents, call your API, send a message. Each ability is a separate tool with a clear name and description.
- Start with one or two tools: the more there are, the more often the model picks the wrong one and the more each request costs.
Sign up for RuAPI and create a key
Create an account at www.ruapi.ai with email, Google, Yandex or Telegram. A new account usually gets $0.05 right away for deepseek-flash, claude-haiku-5-5 and gpt-6-luna — so you can test your first agent before paying. The other models unlock after a top-up from 5 USDT; to buy USDT with rubles via SBP, see docs.ruapi.ai/en/buy-usdt.
Console → “API keys” → “Create key”. Turn off “Unlimited” in the “Budget” block and enter an amount: if the agent gets stuck in a loop, spending stops there.


The no-code path: n8n, Dify, Langflow or Flowise
- n8n: create OpenAI credentials — API Key: your RuAPI key, Base URL: https://www.ruapi.ai/v1. Add an AI Agent node and connect to it an OpenAI Chat Model with the deepseek-flash model and the tools you need (HTTP Request, Google Sheets, vector store search). Details: www.ruapi.ai/n8n-v-rossii.
- Dify, Langflow and Flowise are set up the same way: an OpenAI-compatible provider, the same address with /v1 and the key. Guides: www.ruapi.ai/dify-v-rossii, www.ruapi.ai/langflow-v-rossii and www.ruapi.ai/flowise-v-rossii.
- All four programs can be installed on your own computer or server; their licenses differ — read the terms before commercial use.
The code path: Python and the OpenAI SDK
- Install the package: pip install openai. In the client set base_url="https://www.ruapi.ai/v1" and your RuAPI key.
- Describe the tools in the tools parameter (name, description, parameters as JSON Schema) and write a loop like in the example above: call the model → run the tool_calls → put the result back into messages.
- Cap the number of steps (5 in the example) and check the arguments the model sends before performing an action.
- When the tools and steps become many, move to a framework: LangChain and LangGraph connect with the same address and key — www.ruapi.ai/langchain-v-rossii.
Test the agent and set limits on it
- Run 10–20 typical requests and check in the RuAPI Console request log how many steps and tokens each one took.
- Perform dangerous actions — payments, deletion, mass mailing — only after a human confirms.
- Do not put passwords or keys into the system prompt: a user can coax them out of the model.
- If the agent is reachable from outside (a bot, a widget on a website), limit the number of messages per user — otherwise other people’s requests will spend your balance.
Addresses and keys: docs.ruapi.ai/en/quickstart · n8n: docs.ruapi.ai/en/integrations/n8n · caching: docs.ruapi.ai/en/prompt-caching
Three ways to make an agent
No-code
n8n — automations and the AI Agent node
Dify — chatbots and knowledge bases
Langflow, Flowise — flows built from blocks
With code
OpenAI SDK + a loop with tools
LangChain / LangGraph
base_url: https://www.ruapi.ai/v1
A ready-made agent
Hermes Agent, OpenClaw — a personal assistant
Claude Code, Cline — an agent for code
they connect with the same key
Model prices for AI agents
Models that support tool calling. Prices are in US dollars per 1M tokens, from the RuAPI pricing page; only the tokens you use are deducted.
| model | input $/M | output $/M |
|---|---|---|
| deepseek-flash | $0.17 cache read $0.0120 | $1.44 |
| gpt-6-luna | $0.12 cache read $0.0120 >272K: $0.24 | $0.60 >272K: $0.90 |
| qwen3.8-flash | $0.14 cache read $0.0288 | $0.49 |
| claude-haiku-5-5 | $0.12 cache read $0.0120 >100K: $0.60 | $0.60 >100K: $3.00 |
| claude-sonnet-5-5 | $2.40 cache read $0.12 | $12.00 |
| gpt-6.1-sol | $2.40 cache read $0.12 >272K: $4.80 | $12.00 >272K: $18.00 |
Take a 4-step task: about 3,000 input tokens at each step (history and tool descriptions) and 300 tokens of reply — 12,000 input and 1,200 output tokens in total. By our estimate, that is about $0.004 on deepseek-flash and about $0.043 on claude-sonnet-5-5, not counting the cache. So it pays to give simple steps to an inexpensive model and bring in a strong one where the agent makes mistakes.
The grey “>272K” row is the vendor’s long-prompt rate: if the prompt is over the threshold, the whole request is billed at that rate.
