Description

This endpoint processes messages for a specific agent, generating a response using one of your AI agents.

Endpoint

POST /api/v1/agents/generate-completion

Headers

  • Content-Type: application/json
  • Authorization: Bearer <API_KEY> (required)

Request Body

{
  "messages": [
    {
      "role": "string",
      "content": "string"
    }
  ],
  "agentId": "string",
  "parseJson": "boolean"
}
  • messages: An array of message objects, each containing:
    • role: Either “user” or “assistant”
    • content: The content of the message
  • agentId: The unique identifier of the agent to use for processing
  • parseJson: Whether to try and parse the JSON in the response into a JSON object

Responses

Success (200 OK)

Returns the generated response and usage information.

{
  "parsedJson": "object",
  "text": "string",
  "stepsTaken": "number",
  "steps": [
    {
      "text": "string",
      "toolCalls": "array",
      "toolResults": "array",
      "finishReason": "string",
      "usage": "object"
    }
  ],
  "tokenUsage": {
    "promptTokens": "number",
    "completionTokens": "number",
    "totalTokens": "number"
  },
  "creditUsage": "number"
}

Error Responses

  • 400 Bad Request: If the request is invalid
  • 401 Unauthorized: If the API key is invalid or the user doesn’t have access to the specified agent
  • 403 Forbidden: If the user doesn’t have enough credits
  • 404 Not Found: If the specified agent is not found

Notes

  • This endpoint uses 1 credit per 1000 total tokens used.
  • The agent must belong to the project owned by the authenticated user.

Rate Limiting

Rate limiting is applied based on the user’s subscription.

Example Request

curl -X POST https://app.dumplingai.com/api/v1/agent-message \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
  "messages": [
    {
      "role": "user",
      "content": "Hello, can you help me with a task?"
    }
  ],
  "agentId": "agent_123456",
  "parseJson": false
}'

Example Response

{
  "parsedJson": null,
  "text": "Certainly! I'd be happy to help you with a task. What kind of task do you need assistance with?",
  "stepsTaken": 1,
  "steps": [
    {
      "text": "Certainly! I'd be happy to help you with a task. What kind of task do you need assistance with?",
      "toolCalls": [],
      "toolResults": [],
      "finishReason": "stop",
      "usage": {
        "promptTokens": 20,
        "completionTokens": 15,
        "totalTokens": 35
      }
    }
  ],
  "tokenUsage": {
    "promptTokens": 20,
    "completionTokens": 15,
    "totalTokens": 35
  },
  "creditUsage": 1
}