> For the complete documentation index, see [llms.txt](https://docs.uncodie.com/1.0/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.uncodie.com/1.0/agentbase/introduction/token-and-speed-optimization.md).

# Token and Speed Optimization

Token saving capabilities and recommendations

## Calling functions directly

After a function is created you can make direct usage of the function:

<mark style="color:green;">`POST`</mark> `/function`

A simple token optimization involves "turning off" all unnecessary agents for the function or execution context. When the function executes, previously generated code ensures that calling /function bypasses any code generation and testing agents, allowing direct API execution.

**Headers**

| Name          | Value              |
| ------------- | ------------------ |
| Content-Type  | `application/json` |
| Authorization | `Bearer <token>`   |

**Body**

<table><thead><tr><th width="218">Name</th><th width="94">Type</th><th width="100" data-type="checkbox">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>function</code></td><td>string</td><td>true</td><td>Name of the function</td></tr><tr><td><code>data</code></td><td>object</td><td>false</td><td>The data example or parameters for your function to work</td></tr><tr><td><code>previous_agents</code></td><td>array</td><td>false</td><td>The Agents in order that will be executed before the function is called</td></tr><tr><td><code>active_agents</code></td><td>array</td><td>false</td><td>The Agents in order that will be executed after the function is called and before the return is send, the can alter the return for the client or call new functions</td></tr><tr><td><code>following_agents</code></td><td>array</td><td>false</td><td>Asynchronous agents to execute after the function is executed and the return send to the client</td></tr><tr><td><code>version</code></td><td>number</td><td>false</td><td>The version of the function to execute</td></tr><tr><td><code>bearer_token</code></td><td>string</td><td>false</td><td>Auth0 user session token to validate and ACL to database</td></tr></tbody></table>

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
  "run_id": 1,
  "return": {
    "message" : "message example"
  },
  "status" : {
    "code" : 5,
    "status" : "completed",
  },
  "error": null
}
```

{% endtab %}

{% tab title="400" %}

```
{
  "error": "Invalid request"
}
```

{% endtab %}
{% endtabs %}
