claude-api使用介绍
- 2026-02-18 21:18:00
- admin
- 原创 227
一、claude-api使用介绍
1、入门帮助:https://platform.claude.com/docs/en/get-started
2、发送消息示例:https://platform.claude.com/docs/en/build-with-claude/working-with-messages
3、上传文件示例:https://platform.claude.com/docs/en/build-with-claude/files
4、结构化输出:https://platform.claude.com/docs/en/build-with-claude/structured-outputs
5、发送消息支持:basic单条消息,multiple多轮对话,prefill预填充结果,vision解析图片;
6、输出结果约束:prefill预填充结果,structured-output结构化输出,system系统提示词;
7、安装依赖:pip install anthropic
使用工具:
1、工具概况:https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview
2、工具原理:https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works
3、工具调用:https://platform.claude.com/docs/en/agents-and-tools/tool-use/build-a-tool-using-agent
4、工具开发:https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools
5、工具分类:User-defined用户自定义工具,Anthropic-schema客户端内置工具,Server-executed服务端执行工具;
6、工具配置:defer_loading延迟加载,allowed_callers限制调用方,strict严格校验模式,cache_control缓存调用结果;
发送消息接口:https://platform.claude.com/docs/en/api/python/messages/create
发送消息接口:messages.create(**kwargs) -> Message
1、max_tokens,最大生成多少token,防止消耗过多token;
2、messages,消息内容,消息数组主要是为了支持上下文;
3、system,系统提示词,不设置时使用默认的系统提示词;
4、output_config,设置努力级别,设置输出格式schema;
5、stop_sequences,生成的内容出现这些字符串,生成立即停止;
6、tool_choice,控制模型如何使用工具,比如必须调用指定工具;
7、tools,定义模型可以调用的工具列表,允许调用的工具列表;