How to Build an Intelligent GPT Company Assistant with handelsregister.ai

7 min läsning

Create your own GPT assistant in just a few steps, retrieving official company data directly from the German Handelsregister.

Den här artikeln finns på engelska.

Introduction

Customer communication has changed a lot in recent years. More and more people expect instant, precise and reliable answers to their questions in chats and messenger apps, around the clock. This is exactly where GPT assistants come in: they enable automated, intelligent conversations with your customers. But what if someone wants to know more about your own company or about other businesses? Ordinary web searches often return outdated or incomplete data. That is why it makes sense to source official company information directly from the German commercial register (Handelsregister), and this is exactly where the handelsregister.ai API helps you.

In this blog post, you'll learn step by step how to build your own company assistant using the GPT Responses API (with function calling) and handelsregister.ai. Best of all: you don't need to be a full-time developer or IT professional to understand the basics and run your first experiments.


Overview: what do you need?

  1. OpenAI's GPT Responses API
    – So that your chat assistant understands, in natural language, what users want to know.
  2. The handelsregister.ai API
    – So that you can retrieve official, in-depth company information directly from the Handelsregister.

Depending on the question, your chat assistant can then automatically request the right data and provide real-time information, without you ever having to maintain data manually.


Step 1: Understand GPT function calling

Before you get started, it helps to understand exactly how GPT function calling works:

  • Instead of only returning "ready-made" answers, the GPT model can call its own functions to retrieve current data or perform actions.
  • As soon as the model recognizes that a user request concerns a particular domain (e.g., company data), it creates a function call.
  • You define in advance what the function is called and which parameters are passed.

This approach keeps your system flexible: when new questions or requirements come up, the model can respond via function calls without you having to rewrite all of your code every time.


Step 2: Create the function definition ("tools") for handelsregister.ai

So that GPT knows that and how it should call the handelsregister.ai API, you create a function definition. This definition "explains" to the model how the API call is structured and which parameters are allowed.

Tip: Use English variable names in your code. The parameter descriptions, however, can be written in your users' language, German for example; GPT will still understand what they mean.

Here is a Python example of how to define the tools for the GPT assistant:

tools = [{
    "type": "function",
    "name": "fetch_company_data",
    "description": "Retrieve detailed information about a company from handelsregister.ai",
    "parameters": {
        "type": "object",
        "properties": {
            "company_name": {
                "type": "string",
                "description": "Full company name"
            },
            "features": {
                "type": "array",
                "description": "Additional information to retrieve",
                "items": {
                    "type": "string",
                    "enum": [
                        "related_persons",
                        "financial_kpi",
                        "balance_sheet_accounts",
                        "profit_and_loss_account"
                    ]
                }
            }
        },
        "required": ["company_name"],
        "additionalProperties": False
    },
    "strict": True
}]

What exactly happens here?

  • type: "function" – This tells GPT that this entry is a function.
  • name: "fetch_company_data" – This is the name of our function. GPT will later recognize exactly this name.
  • description: A short description so that GPT knows what it is about.
  • parameters: This is where you define which data the function needs.
    • company_name – e.g., "OroraTech GmbH"
    • features – a list of possible additional features (e.g., managing director data, financials, etc.)
  • strict: True ensures that GPT passes the parameters correctly and in line with the schema.

Step 3: A Python function to retrieve data from handelsregister.ai

Now that you have defined the "tools", you still need a function in your code that sends the actual request to the Handelsregister API. This way, your chat assistant can not only suggest a function call but actually deliver data.

import requests
import json

API_KEY = "<YOUR_API_KEY>"

def fetch_company_data(company_name, features=None):
    url = "https://handelsregister.ai/api/v1/fetch-organization"
    params = {
        "api_key": API_KEY,
        "q": company_name
    }
    if features:
        # Add features to the parameters as a list
        params["feature"] = features

    response = requests.get(url, params=params)
    
    if response.status_code == 200:
        return response.json()
    else:
        return {"error": f"API error: {response.status_code}"}

Explanation

  1. API_KEY: This is where you enter your own key, which you received from handelsregister.ai.
  2. params: In this dictionary, you put together the parameters for the request.
  3. response: You call the API with requests.get(). If everything goes well, we convert the result to JSON so that GPT can process it later.

Step 4: Call GPT Responses and handle function calls

Now that you know how the tools (functions) are defined and what the actual call to handelsregister.ai looks like, we need to bring these steps together. This lets your GPT model recognize when it makes sense to pull the data.

4.1 Call GPT with your tools

from openai import OpenAI

client = OpenAI()

input_messages = [{
    "role": "user",
    "content": "Who are the current managing directors of OroraTech GmbH?"
}]

response = client.responses.create(
    model="gpt-4o",
    input=input_messages,
    tools=tools
)

print(response.output)

Here is what happens:

  • input_messages contains the user's question.
  • tools is the list containing the single function fetch_company_data that you defined earlier.
  • GPT sees the question and can decide whether it wants to use your function.

Possible output:

[
  {
    "type": "function_call",
    "id": "fc_xyz123",
    "call_id": "call_xyz123",
    "name": "fetch_company_data",
    "arguments": "{\"company_name\":\"OroraTech GmbH\",\"features\":[\"related_persons\"]}"
  }
]

This means GPT wants to call the fetch_company_data function and request information about "related_persons" (e.g., managing directors).

4.2 Execute the function call

Now you take the arguments suggested by GPT and actually call your fetch_company_data function:

import json

tool_call = response.output[0]
args = json.loads(tool_call["arguments"])  # JSON decoding

result = fetch_company_data(args["company_name"], args.get("features"))

result now contains real data from handelsregister.ai.

4.3 Return the results to GPT

So that GPT can phrase the answer in natural language, you still need to pass the retrieved data back to GPT:

input_messages.append(tool_call)  # Append the "function call" message to the history
input_messages.append({
    "type": "function_call_output",
    "call_id": tool_call["call_id"],
    "output": json.dumps(result)
})

final_response = client.responses.create(
    model="gpt-4o",
    input=input_messages,
    tools=tools
)

print(final_response.output_text)

Based on this data, GPT can now give an answer such as:

"The current managing directors of OroraTech GmbH are Martin Langer, Viktor Gauk, Axel Justus Oswald Roenneke and Thomas Grübler."


Step 5: Application and outlook

What kinds of questions can your assistant answer now?

  • Management: "Who has been managing director of a company, and since when?"
  • Financial KPIs: "How much equity did the company have last year?"
  • Balance sheet data: "Which assets does the company list on its balance sheet?"
  • Contact information: "Which official email address does the company use?"

This lets you offer your users information that goes far beyond simple web searches, within seconds and without manual upkeep.

Benefits at a glance

  1. Automated, reliable answers: GPT recognizes the question, fetches the data and formulates an answer.
  2. Official data: handelsregister.ai draws directly on the German commercial register.
  3. Scalability: No matter how many requests you get per day, the system can grow with you.
  4. Ease of use: You don't have to search yourself for every new question; your assistant takes care of it.

Conclusion

With these five steps, you have laid the foundation for an intelligent company assistant that can deliver real, official and up-to-date data. By combining GPT Responses and handelsregister.ai, you offer your users enormous added value: automated, verified information whenever they need it.

Don't hesitate to adapt and extend the code snippets shown here. It's worth taking the next step toward automated, knowledgeable chat assistants. Have fun building it!


Further links and resources

Related guides