跳转到主要内容
本页介绍 Dedalus 应用程序编程接口 API 返回的所有响应模式。所有响应都采用与 OpenAI 兼容的格式。
## Dedalus Runner
RunResult
object
在非流式传输模式下执行 tool 时由 DedalusRunner 返回的响应对象。
Example
from dedalus_labs import Dedalus, DedalusRunner

client = Dedalus(api_key="YOUR_API_KEY")
runner = DedalusRunner(client)

def get_weather(location: str) -> str:
    """获取指定地点的当前天气。"""
    return f"The weather in {location} is sunny and 72°F"

result = runner.run(
    input="What's the weather like in San Francisco?",
    tools=[get_weather],
    model="openai/gpt-5-nano",
    max_steps=5
)

# Access result properties
print(result.final_output)   # "The weather in San Francisco is sunny and 72°F"
print(result.steps_used)     # e.g., 2
print(result.tools_called)   # ["get_weather"]
print(result.tool_results)   # [{"name": "get_weather", "result": "The weather...", "step": 1}]
Accessing Message History
import json

# 打印完整的对话历史记录
for msg in result.messages:
    role = msg.get("role")
    content = msg.get("content", "")

    if role == "user":
        print(f"User: {content}")
    elif role == "assistant":
        if msg.get("tool_calls"):
            tools = [tc["function"]["name"] for tc in msg["tool_calls"]]
            print(f"Assistant: [calling {', '.join(tools)}]")
        else:
            print(f"Assistant: {content}")
    elif role == "tool":
        print(f"Tool Result: {content[:100]}...")

# 将消息历史记录存储为 JSON 以便日志记录/调试
with open("conversation_log.json", "w") as f:
    json.dump(result.messages, f, indent=2)

# 使用消息历史记录继续对话
follow_up = runner.run(
    messages=result.to_input_list(),  # 传递先前的对话
    input="What about New York?",      # 添加新用户消息
    tools=[get_weather],
    model="openai/gpt-5-nano"
)
Example Response
{
	"final_output": "The weather in San Francisco is sunny and 72°F",
	"tool_results": [
		{
			"name": "get_weather",
			"result": "The weather in San Francisco is sunny and 72°F",
			"step": 1
		}
	],
	"steps_used": 2,
	"tools_called": ["get_weather"],
	"messages": [
		{ "role": "user", "content": "旧金山的天气怎么样?" },
		{
			"role": "assistant",
			"tool_calls": [
				{
					"id": "call_abc123",
					"type": "function",
					"function": {
						"name": "get_weather",
						"arguments": "{\"location\": \"San Francisco\"}"
					}
				}
			]
		},
		{
			"role": "tool",
			"tool_call_id": "call_abc123",
			"content": "The weather in San Francisco is sunny and 72°F"
		},
		{
			"role": "assistant",
			"content": "The weather in San Francisco is sunny and 72°F"
		}
	],
	"intents": null
}

聊天补全

ChatCompletion
object
非流式聊天补全的完整响应对象。
Example
{
	"id": "chatcmpl-abc123",
	"object": "chat.completion",
	"created": 1677652288,
	"model": "openai/gpt-5-nano",
	"choices": [
		{
			"index": 0,
			"message": {
				"role": "assistant",
				"content": "Hello! I'm doing well, thank you for asking."
			},
			"finish_reason": "stop"
		}
	],
	"usage": {
		"prompt_tokens": 13,
		"completion_tokens": 12,
		"total_tokens": 25
	}
}

ChatCompletionChunk
object
用于流式传输补全结果(stream=true)的分片响应。
Example
{
	"id": "chatcmpl-abc123",
	"object": "chat.completion.chunk",
	"created": 1677652288,
	"model": "openai/gpt-5-nano",
	"choices": [
		{
			"index": 0,
			"delta": {
				"content": "Hello"
			},
			"finish_reason": null
		}
	]
}

向量嵌入

CreateEmbeddingResponse
object
向量嵌入创建请求的响应对象。
Example
{
	"object": "list",
	"data": [
		{
			"object": "embedding",
			"embedding": [0.0023064255, -0.009327292, -0.0028842222],
			"index": 0
		}
	],
	"model": "openai/text-embedding-3-small",
	"usage": {
		"prompt_tokens": 8,
		"total_tokens": 8
	}
}

模型

ListModelsResponse
object
用于列出可用模型的响应对象,包含关于能力和路由的丰富元数据。
Example
{
	"object": "list",
	"data": [
		{
			"id": "openai/gpt-4o",
			"provider": "openai",
			"created_at": "1970-01-01T00:00:00Z",
			"display_name": null,
			"description": null,
			"capabilities": {
				"text": true,
				"vision": null,
				"image_generation": null,
				"audio": null,
				"tools": null,
				"structured_output": null,
				"streaming": null,
				"thinking": null,
				"input_token_limit": null,
				"output_token_limit": null
			},
			"provider_info": {
				"status": "enabled",
				"upstream_api": "openai/chat/completions"
			}
		},
		{
			"id": "openai/o1",
			"provider": "openai",
			"created_at": "1970-01-01T00:00:00Z",
			"capabilities": {
				"text": true,
				"thinking": true
			},
			"provider_info": {
				"status": "enabled",
				"upstream_api": "openai/chat/completions"
			}
		},
		{
			"id": "anthropic/claude-opus-4-5",
			"provider": "anthropic",
			"created_at": "1970-01-01T00:00:00Z",
			"capabilities": {
				"text": true,
				"vision": true,
				"tools": true
			},
			"provider_info": {
				"status": "enabled",
				"upstream_api": "anthropic/messages"
			}
		}
	]
}

图像

ImagesResponse
object
图像生成请求的响应对象。
Example
{
	"created": 1677652288,
	"data": [
		{
			"url": "https://images.example.com/abc123.png",
			"revised_prompt": "A cute baby sea otter floating on its back in calm blue water"
		}
	]
}

音频

TranscriptionResponse
object
音频转录请求的响应对象。
Example
{
	"text": "Hello, this is a test of audio transcription."
}

TranslationResponse
object
用于音频翻译请求的响应对象(始终翻译为英语)。
Example
{
	"text": "Hello, this is a test of audio translation."
}

错误

ErrorResponse
object
所有端点在出错时都可能返回符合此结构的错误对象。
Example
{
	"error": {
		"message": "提供的 API 密钥无效",
		"type": "authentication_error",
		"code": "invalid_api_key"
	}
}
Last modified on April 11, 2026