v1
chat

Create

Create a chat completion using the Agent framework.

This endpoint provides a vendor-agnostic chat completion API that works with 100+ LLM providers via the Agent framework. It supports both single and multi-model routing, client-side and server-side tool execution, and integration with MCP (Model Context Protocol) servers.

Features: - Cross-vendor compatibility (OpenAI, Anthropic, Cohere, etc.) - Multi-model routing with intelligent agentic handoffs - Client-side tool execution (tools returned as JSON) - Server-side MCP tool execution with automatic billing - Streaming and non-streaming responses - Advanced agent attributes for routing decisions - Automatic usage tracking and billing

Args: request: Chat completion request with messages, model, and configuration http_request: FastAPI request object for accessing headers and state background_tasks: FastAPI background tasks for async billing operations user: Authenticated user with validated API key and sufficient balance

Returns: ChatCompletion: OpenAI-compatible completion response with usage data

Raises: HTTPException: - 401 if authentication fails or insufficient balance - 400 if request validation fails - 500 if internal processing error occurs

Billing: - Token usage billed automatically based on model pricing - MCP tool calls billed separately using credits system - Streaming responses billed after completion via background task

Example: Basic chat completion: ```python import dedalus_labs

client = dedalus_labs.Client(api_key="your-api-key")

completion = client.chat.create(
    model="gpt-4",
    input=[{"role": "user", "content": "Hello, how are you?"}],
)

print(completion.choices[0].message.content)
```

With tools and MCP servers:
```python
completion = client.chat.create(
    model="gpt-4",
    input=[{"role": "user", "content": "Search for recent AI news"}],
    tools=[
        {
            "type": "function",
            "function": {
                "name": "search_web",
                "description": "Search the web for information",
            },
        }
    ],
    mcp_servers=["dedalus-labs/brave-search"],
)
```

Multi-model routing:
```python
completion = client.chat.create(
    model=["gpt-4o-mini", "gpt-4", "claude-3-5-sonnet"],
    input=[{"role": "user", "content": "Analyze this complex data"}],
    agent_attributes={"complexity": 0.8, "accuracy": 0.9},
)
```

Streaming response:
```python
stream = client.chat.create(
    model="gpt-4",
    input=[{"role": "user", "content": "Tell me a story"}],
    stream=True,
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")
```
post/v1/chat

Request body

inputobject[] nullable

Input to the model - can be messages, images, or other modalities. Supports OpenAI chat format with role/content structure. For multimodal inputs, content can include text, images, or other media types.

toolsobject[] nullable

List of tools available to the model in OpenAI function calling format. Tools are executed client-side and returned as JSON for the application to handle. Use 'mcp_servers' for server-side tool execution.

mcp_serversstring[] nullable

MCP (Model Context Protocol) server addresses to make available for server-side tool execution. Can be URLs (e.g., 'https://mcp.example.com') or slugs (e.g., 'dedalus-labs/brave-search'). MCP tools are executed server-side and billed separately.

temperaturenumber nullable

Sampling temperature (0 to 2). Higher values make output more random, lower values make it more focused and deterministic. 0 = deterministic, 1 = balanced, 2 = very creative.

top_pnumber nullable

Nucleus sampling parameter (0 to 1). Alternative to temperature. 0.1 = only top 10% probability mass, 1.0 = consider all tokens.

ninteger nullable

Number of completions to generate. Note: only n=1 is currently supported.

streamboolean nullable

Whether to stream back partial message deltas as Server-Sent Events. When true, partial message deltas will be sent as chunks in OpenAI format.

stopstring[] nullable

Up to 4 sequences where the API will stop generating further tokens. The model will stop as soon as it encounters any of these sequences.

max_tokensinteger nullable

Maximum number of tokens to generate in the completion. Does not include tokens in the input messages.

presence_penaltynumber nullable

Presence penalty (-2 to 2). Positive values penalize new tokens based on whether they appear in the text so far, encouraging the model to talk about new topics.

frequency_penaltynumber nullable

Frequency penalty (-2 to 2). Positive values penalize new tokens based on their existing frequency in the text so far, decreasing likelihood of repeated phrases.

logit_biasobject nullable

Modify likelihood of specified tokens appearing in the completion. Maps token IDs (as strings) to bias values (-100 to 100). -100 = completely ban token, +100 = strongly favor token.

userstring nullable

Unique identifier representing your end-user. Used for monitoring and abuse detection. Should be consistent across requests from the same user.

guardrailsobject[] nullable

Guardrails to apply to the agent for input/output validation and safety checks. Reserved for future use - guardrails configuration format not yet finalized.

handoff_configobject nullable

Configuration for multi-model handoffs and agent orchestration. Reserved for future use - handoff configuration format not yet finalized.

model_attributesobject nullable

Attributes for individual models used in routing decisions during multi-model execution. Format: {'model_name': {'attribute': value}}, where values are 0.0-1.0. Common attributes: 'intelligence', 'speed', 'cost', 'creativity', 'accuracy'. Used by agent to select optimal model based on task requirements.

agent_attributesobject nullable

Attributes for the agent itself, influencing behavior and model selection. Format: {'attribute': value}, where values are 0.0-1.0. Common attributes: 'complexity', 'accuracy', 'efficiency', 'creativity', 'friendliness'. Higher values indicate stronger preference for that characteristic.

max_turnsinteger nullable

Maximum number of turns for agent execution before terminating (default: 10). Each turn represents one model inference cycle. Higher values allow more complex reasoning but increase cost and latency.

Example request

{
  "input": [
    {
      "content": "Hello, how are you?",
      "role": "user"
    }
  ],
  "tools": [
    {
      "function": {
        "description": "Get current weather for a location",
        "name": "get_weather",
        "parameters": {
          "properties": {
            "location": {
              "description": "City name",
              "type": "string"
            }
          },
          "required": [
            "location"
          ],
          "type": "object"
        }
      },
      "type": "function"
    }
  ],
  "mcp_servers": [
    "dedalus-labs/brave-search",
    "dedalus-labs/github-api"
  ],
  "top_p": 0.1,
  "n": 1,
  "stream": true,
  "stop": [
    "\\n",
    "END"
  ],
  "max_tokens": 100,
  "presence_penalty": -0.5,
  "frequency_penalty": -0.5,
  "logit_bias": {
    "50256": -100
  },
  "user": "user-123",
  "model_attributes": {
    "claude-3-5-sonnet": {
      "cost": 0.7,
      "creativity": 0.8,
      "intelligence": 0.95
    },
    "gpt-4": {
      "cost": 0.8,
      "intelligence": 0.9,
      "speed": 0.6
    },
    "gpt-4o-mini": {
      "cost": 0.2,
      "intelligence": 0.7,
      "speed": 0.9
    }
  },
  "agent_attributes": {
    "accuracy": 0.9,
    "complexity": 0.8,
    "efficiency": 0.7
  },
  "max_turns": 5
}

Response

Successful Response

idstring required
createdinteger required
modelstring required
object'chat.completion' required
service_tier'auto' | 'default' | 'flex' | 'scale' | 'priority' nullable
system_fingerprintstring nullable

Changes