For the complete documentation index, see llms.txt. This page is also available as Markdown.

External API

Create, list, link, and delete External API functions so your characters can call custom Python code during conversations.

External API functions are small Python handlers your character can call as tools during a conversation. Create a function once, link it to one or more characters, and the model decides when to run it based on the function name and description.

Typical flow:

  1. Create a function with /functions/create/

  2. Link it to a character with /character/update (status: "active")

  3. List functions (optionally filtered by character) with /functions/list/

  4. Unlink it from a character with /character/update (status: "inactive"), or delete it entirely with /functions/delete/

For the Playground UI walkthrough and example handlers (weather, sports scores, Jira), see External API.

Hard limits (supported models, Python runtime, libraries, schema, caps) are documented once on External API limitations.

Writing functions

Functions run in a sandboxed Python 3.11 runtime. Write plain Python, keep the surface area small, and return JSON-serializable data the model can read back into the conversation.

For the full limit list (allowed libraries, line cap, model support, character caps), see External API limitations.

Entry point: handle_event

Every function must define a top-level function named handle_event that takes one argument. That argument is a dict of the values the model filled in from your input_description.

def handle_event(inputs):
    # `inputs` is a dict of the parameters defined in input_description.
    # Call your external API here and return a JSON-serializable dict.
    return {"result": "ok"}

Requirements:

  • The name must be exactly handle_event

  • It must accept a single parameter (commonly named inputs or data)

  • Return a JSON-serializable value, almost always a dict

  • Do not rely on global mutable state across calls — each invocation is independent

Minimal example that reads one parameter and hits an external API:

Input description schema

input_description tells the model which arguments it can (and must) pass into handle_event. On create/update it is sent as a JSON string, not a nested object. The decoded JSON must match this schema:

What that means in practice:

Field
Rules

parameters

Object whose keys are parameter names. Extra keys outside this map are rejected (additionalProperties: false).

Parameter name

Must match ^[a-zA-Z_][a-zA-Z0-9_]*$ (letter or _ first, then letters, digits, or _).

parameters.<name>.type

One of: string, integer, boolean, object, array.

parameters.<name>.description

Non-empty string the model uses to decide what value to pass.

required

Array of parameter names that must be present. Names listed here should also exist under parameters.

The same rules are summarized on External API limitations.

Example input_description (as an object — stringify it before sending in the request body):

In Python when calling create:

Keep parameter descriptions concrete. The model picks arguments from those descriptions, so vague text like "a value" leads to bad calls. Prefer examples and units in the description string.


Create a function

POST https://api.convai.com/functions/create/

Creates a new External API function on your account. The function is not attached to any character until you link it.

Headers

Name
Type
Description

CONVAI-API-KEY*

String

The unique api-key provided for every user. Found under the Key icon when logged into your Convai account.

Content-Type*

String

Must be application/json

Request body

Name
Type
Description

name*

String

Display name of the function. Prefer a clear verb phrase the model can match (for example Get Weather).

description*

String

When the character should call this function. Used by the model for tool selection.

language*

String

Implementation language. Only python is supported.

source_code*

String

Full Python 3.11 source, including handle_event. Max 400 lines. Stdlib + requests only. See Writing functions and limitations.

input_description*

String

JSON string describing parameters. See Input description schema and limitations.

Example payload

Other common 400 messages:

  • Field input_description must be a valid json string

  • Language pythonx not supported

  • Schema errors from an invalid input_description

  • Source code validation failures (empty, over 400 lines, or blocked as malicious)

Here are some sample codes to demonstrate the request format for the endpoint -->


List functions

POST https://api.convai.com/functions/list/

Returns the External API functions on your account. Pass character_id to include each function's link status for that character (active or inactive).

Headers

Name
Type
Description

CONVAI-API-KEY*

String

The unique api-key provided for every user. Found under the Key icon when logged into your Convai account.

Request body

All fields are optional. An empty body lists every function on the account.

Name
Type
Description

character_id

String

If set, each function includes status relative to this character (active / inactive).

per_page

Integer

Page size. Defaults to -1 (return all). When set to a positive value, pagination fields are added.

page

Integer

Page number, starting at 1. Used only when per_page is not -1. Default 1.

Example payload

total_pages, per_page, page, and total are only present when per_page is a positive integer.

Here are some sample codes to demonstrate the request format for the endpoint -->


POST https://api.convai.com/character/update

Attach one or more External API functions to a character through the existing Character Base API update endpoint. Once linked (status: "active"), the model can call those functions during conversation.

A character can have at most 128 active functions. You can link several functions in one request, and you can mix link and unlink entries together.

Headers

Name
Type
Description

CONVAI-API-KEY*

String

The unique api-key provided for every user. Found under the Key icon when logged into your Convai account.

Content-Type

String

application/json

Request body

Name
Type
Description

charID*

String

Character to update.

functions

Array

List of function configs. Each item needs id (function UUID) and status set to "active".

Example payload

Also returned for invalid configs, for example:

  • Functions must be a list of configurations

  • Missing required fields in function configuration: id

  • Function status must be one of: active, inactive

  • Duplicate function ID found: <id>

Here are some sample codes to demonstrate the request format for the endpoint -->

After linking, confirm with /functions/list/ and character_id set — linked functions show "status": "active".


POST https://api.convai.com/character/update

Disconnect a function from a character without deleting it from your account. Same endpoint as linking; set status to "inactive".

After unlinking, the character can no longer call that function. The function stays available to re-link later, or to attach to other characters.

Headers

Name
Type
Description

CONVAI-API-KEY*

String

The unique api-key provided for every user. Found under the Key icon when logged into your Convai account.

Content-Type

String

application/json

Request body

Name
Type
Description

charID*

String

Character to update.

functions

Array

List of function configs. Each item needs id (function UUID) and status set to "inactive".

Example payload

Here are some sample codes to demonstrate the request format for the endpoint -->

Confirm with /functions/list/ and character_id set — unlinked functions show "status": "inactive".

Unlinking only removes the character association. To remove the function from your account entirely (and every character it is linked to), use Delete a function.


Delete a function

POST https://api.convai.com/functions/delete/

Deletes a function you own and removes every character association for it. This cannot be undone.

Headers

Name
Type
Description

CONVAI-API-KEY*

String

The unique api-key provided for every user. Found under the Key icon when logged into your Convai account.

Content-Type*

String

Must be application/json

Request body

Name
Type
Description

function_id*

String

UUID of the function to delete

Example payload

Here are some sample codes to demonstrate the request format for the endpoint -->

To disconnect a function from a character without deleting it, use Unlink functions from a character.

Last updated

Was this helpful?