Download the PHP package tourze/volcano-ark-api-bundle without Composer
On this page you can find all versions of the php package tourze/volcano-ark-api-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package volcano-ark-api-bundle
Volcano Ark API Bundle
中文
一个用于集成 Volcano Ark(火山方舟)API 的 Symfony Bundle,提供了完整的 API 密钥管理、使用量统计和审计日志功能。
功能特性
- 🔑 API 密钥管理 - 支持多个 API 密钥的创建、激活、停用和自动轮换
- 📊 使用量统计 - 实时统计 API 调用次数、Token 使用量和成本估算
- 🔍 审计日志 - 完整的 API 调用审计追踪
- 🎯 OpenAI 兼容 - 提供兼容 OpenAI SDK 的客户端接口
- 🖥️ 管理后台 - 集成 EasyAdmin 的完整管理界面
- 🛠️ 命令行工具 - 丰富的 CLI 命令支持
- 🔄 自动同步 - 支持使用量和审计日志的自动同步
安装
配置
基础配置
Doctrine 配置
使用方法
命令行工具
API 密钥管理
数据同步
服务层使用
使用 ApiKeyService
使用 UsageService
使用 AuditLogService
OpenAI 兼容客户端
自定义客户端
数据模型
ApiKey
API 密钥实体,包含以下字段:
id: 主键 IDname: 密钥名称provider: 服务提供商(默认:volcano_ark)apiKey: API 密钥值(加密存储)secretKey: 密钥值(加密存储)region: 区域(默认:cn-beijing)isActive: 是否激活状态usageCount: 使用次数统计lastUsedTime: 最后使用时间description: 描述信息metadata: 扩展元数据(JSON 格式)createdAt: 创建时间updatedAt: 更新时间
ApiKeyUsage
API 密钥使用统计实体,包含以下字段:
id: 主键 IDapiKey: 关联的 API 密钥usageHour: 使用小时(按小时聚合)endpointId: 端点 IDpromptTokens: 提示 Token 数量completionTokens: 完成 Token 数量totalTokens: 总 Token 数量requestCount: 请求次数estimatedCost: 估算成本createdAt: 创建时间updatedAt: 更新时间
AuditLog
审计日志实体,包含以下字段:
id: 主键 IDapiKey: 关联的 API 密钥timestamp: 请求时间戳method: 请求方法endpoint: 请求端点requestId: 请求 IDpromptTokens: 提示 Token 数量completionTokens: 完成 Token 数量totalTokens: 总 Token 数量model: 使用的模型cost: 本次请求成本metadata: 额外元数据(JSON 格式)createdAt: 创建时间updatedAt: 更新时间
管理后台
Bundle 集成了 EasyAdmin,提供完整的管理界面:
- API 密钥管理 - 查看、创建、编辑、激活/停用 API 密钥
- 使用量统计 - 查看详细的使用量报告和图表
- 审计日志 - 浏览和搜索完整的审计记录
访问 /admin 即可进入管理后台。
事件系统
Bundle 提供了丰富的事件系统,允许您在关键节点执行自定义逻辑:
ApiKeyUsedEvent
当 API 密钥被使用时触发:
UsageSyncedEvent
当使用量数据同步完成时触发。
AuditLogSyncedEvent
当审计日志同步完成时触发。
测试
性能优化
缓存策略
Bundle 内置了多种缓存策略来优化性能:
- API 密钥缓存 - 缓存当前激活的 API 密钥
- 使用量缓存 - 缓存频繁查询的使用量数据
- 模型列表缓存 - 缓存可用的模型列表
异步处理
对于大量的数据同步操作,建议使用队列系统:
安全考虑
- 密钥加密 - 所有 API 密钥和密钥值在数据库中都经过加密存储
- 访问控制 - 管理后台需要适当的权限验证
- 审计追踪 - 所有 API 调用都有完整的审计日志
- 密钥轮换 - 支持自动和手动的密钥轮换
故障排除
常见问题
-
No active API key found
- 确保至少有一个激活的 API 密钥
- 检查密钥的
isActive字段是否为true
-
API request failed
- 验证 API 密钥和密钥值是否正确
- 检查网络连接和防火墙设置
- 确认区域设置是否正确
- Database connection errors
- 确保 Doctrine 配置正确
- 检查数据库连接和权限
调试模式
启用调试模式获取更详细的日志信息:
贡献
欢迎提交 Issue 和 Pull Request!
许可证
MIT
All versions of volcano-ark-api-bundle with dependencies
PHP Build Version
Package Version
Requires
doctrine/dbal Version
^4.0
doctrine/doctrine-bundle Version ^2.13
doctrine/orm Version ^3.0
doctrine/persistence Version ^4.1
easycorp/easyadmin-bundle Version ^4
knplabs/knp-menu Version ^3.7
monolog/monolog Version ^3.1
psr/log Version ^3|^2|^1
symfony/cache-contracts Version ^3
symfony/config Version ^7.3
symfony/console Version ^7.3
symfony/dependency-injection Version ^7.3
symfony/doctrine-bridge Version ^7.3
symfony/event-dispatcher Version ^7.3
symfony/framework-bundle Version ^7.3
symfony/http-client Version ^7.3
symfony/http-client-contracts Version ^3.6
symfony/http-foundation Version ^7.3
symfony/http-kernel Version ^7.3
symfony/lock Version ^7.3
symfony/property-access Version ^7.3
symfony/routing Version ^7.3
symfony/validator Version ^7.3
symfony/yaml Version ^7.3
tourze/bundle-dependency Version 1.*
tourze/doctrine-async-insert-bundle Version 1.0.*
tourze/doctrine-indexed-bundle Version 1.0.*
tourze/doctrine-timestamp-bundle Version 1.0.*
tourze/easy-admin-menu-bundle Version 1.0.*
tourze/http-client-bundle Version 1.0.*
tourze/open-ai-contracts Version 1.0.*
tourze/symfony-dependency-service-loader Version 1.0.*
tourze/symfony-routing-auto-loader-bundle Version 1.0.*
doctrine/doctrine-bundle Version ^2.13
doctrine/orm Version ^3.0
doctrine/persistence Version ^4.1
easycorp/easyadmin-bundle Version ^4
knplabs/knp-menu Version ^3.7
monolog/monolog Version ^3.1
psr/log Version ^3|^2|^1
symfony/cache-contracts Version ^3
symfony/config Version ^7.3
symfony/console Version ^7.3
symfony/dependency-injection Version ^7.3
symfony/doctrine-bridge Version ^7.3
symfony/event-dispatcher Version ^7.3
symfony/framework-bundle Version ^7.3
symfony/http-client Version ^7.3
symfony/http-client-contracts Version ^3.6
symfony/http-foundation Version ^7.3
symfony/http-kernel Version ^7.3
symfony/lock Version ^7.3
symfony/property-access Version ^7.3
symfony/routing Version ^7.3
symfony/validator Version ^7.3
symfony/yaml Version ^7.3
tourze/bundle-dependency Version 1.*
tourze/doctrine-async-insert-bundle Version 1.0.*
tourze/doctrine-indexed-bundle Version 1.0.*
tourze/doctrine-timestamp-bundle Version 1.0.*
tourze/easy-admin-menu-bundle Version 1.0.*
tourze/http-client-bundle Version 1.0.*
tourze/open-ai-contracts Version 1.0.*
tourze/symfony-dependency-service-loader Version 1.0.*
tourze/symfony-routing-auto-loader-bundle Version 1.0.*
The package tourze/volcano-ark-api-bundle contains the following files
Loading the files please wait ...