@zelailabs/sdk 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -21
- package/README.id.md +304 -0
- package/README.md +231 -95
- package/dist/cjs/account.d.ts +1 -0
- package/dist/cjs/account.js +18 -0
- package/dist/cjs/account.js.map +1 -0
- package/dist/cjs/ban.d.ts +1 -0
- package/dist/cjs/ban.js +18 -0
- package/dist/cjs/ban.js.map +1 -0
- package/dist/cjs/guardrails.d.ts +1 -0
- package/dist/cjs/guardrails.js +18 -0
- package/dist/cjs/guardrails.js.map +1 -0
- package/dist/cjs/index.d.ts +13 -5
- package/dist/cjs/index.js +16 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/errors.js.map +1 -0
- package/dist/cjs/lib/retry.d.ts +24 -0
- package/dist/cjs/lib/retry.js +80 -0
- package/dist/cjs/lib/retry.js.map +1 -0
- package/dist/cjs/{stream.d.ts → lib/stream.d.ts} +1 -1
- package/dist/cjs/lib/stream.js.map +1 -0
- package/dist/{esm → cjs/models}/types.d.ts +60 -0
- package/dist/cjs/{types.js.map → models/types.js.map} +1 -1
- package/dist/cjs/retry.d.ts +1 -0
- package/dist/cjs/retry.js +18 -0
- package/dist/cjs/retry.js.map +1 -0
- package/dist/cjs/sdk/account.d.ts +1 -0
- package/dist/cjs/sdk/account.js +8 -0
- package/dist/cjs/sdk/account.js.map +1 -0
- package/dist/cjs/sdk/ban.d.ts +96 -0
- package/dist/cjs/sdk/ban.js +209 -0
- package/dist/cjs/sdk/ban.js.map +1 -0
- package/dist/cjs/{client.d.ts → sdk/client.d.ts} +36 -1
- package/dist/cjs/{client.js → sdk/client.js} +54 -3
- package/dist/cjs/sdk/client.js.map +1 -0
- package/dist/cjs/sdk/guardrails.d.ts +58 -0
- package/dist/cjs/sdk/guardrails.js +238 -0
- package/dist/cjs/sdk/guardrails.js.map +1 -0
- package/dist/cjs/sdk/worker.d.ts +80 -0
- package/dist/cjs/sdk/worker.js +251 -0
- package/dist/cjs/sdk/worker.js.map +1 -0
- package/dist/cjs/worker.d.ts +1 -0
- package/dist/cjs/worker.js +18 -0
- package/dist/cjs/worker.js.map +1 -0
- package/dist/esm/account.d.ts +1 -0
- package/dist/esm/account.js +2 -0
- package/dist/esm/account.js.map +1 -0
- package/dist/esm/ban.d.ts +1 -0
- package/dist/esm/ban.js +2 -0
- package/dist/esm/ban.js.map +1 -0
- package/dist/esm/guardrails.d.ts +1 -0
- package/dist/esm/guardrails.js +2 -0
- package/dist/esm/guardrails.js.map +1 -0
- package/dist/esm/index.d.ts +13 -5
- package/dist/esm/index.js +8 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/errors.js.map +1 -0
- package/dist/esm/lib/retry.d.ts +24 -0
- package/dist/esm/lib/retry.js +76 -0
- package/dist/esm/lib/retry.js.map +1 -0
- package/dist/esm/{stream.d.ts → lib/stream.d.ts} +1 -1
- package/dist/esm/lib/stream.js.map +1 -0
- package/dist/{cjs → esm/models}/types.d.ts +60 -0
- package/dist/esm/{types.js.map → models/types.js.map} +1 -1
- package/dist/esm/retry.d.ts +1 -0
- package/dist/esm/retry.js +2 -0
- package/dist/esm/retry.js.map +1 -0
- package/dist/esm/sdk/account.d.ts +1 -0
- package/dist/esm/sdk/account.js +2 -0
- package/dist/esm/sdk/account.js.map +1 -0
- package/dist/esm/sdk/ban.d.ts +96 -0
- package/dist/esm/sdk/ban.js +203 -0
- package/dist/esm/sdk/ban.js.map +1 -0
- package/dist/esm/{client.d.ts → sdk/client.d.ts} +36 -1
- package/dist/esm/{client.js → sdk/client.js} +50 -2
- package/dist/esm/sdk/client.js.map +1 -0
- package/dist/esm/sdk/guardrails.d.ts +58 -0
- package/dist/esm/sdk/guardrails.js +234 -0
- package/dist/esm/sdk/guardrails.js.map +1 -0
- package/dist/esm/sdk/worker.d.ts +80 -0
- package/dist/esm/sdk/worker.js +248 -0
- package/dist/esm/sdk/worker.js.map +1 -0
- package/dist/esm/worker.d.ts +1 -0
- package/dist/esm/worker.js +2 -0
- package/dist/esm/worker.js.map +1 -0
- package/package.json +61 -7
- package/dist/cjs/client.js.map +0 -1
- package/dist/cjs/errors.js.map +0 -1
- package/dist/cjs/stream.js.map +0 -1
- package/dist/esm/client.js.map +0 -1
- package/dist/esm/errors.js.map +0 -1
- package/dist/esm/stream.js.map +0 -1
- /package/dist/cjs/{errors.d.ts → lib/errors.d.ts} +0 -0
- /package/dist/cjs/{errors.js → lib/errors.js} +0 -0
- /package/dist/cjs/{stream.js → lib/stream.js} +0 -0
- /package/dist/cjs/{types.js → models/types.js} +0 -0
- /package/dist/esm/{errors.d.ts → lib/errors.d.ts} +0 -0
- /package/dist/esm/{errors.js → lib/errors.js} +0 -0
- /package/dist/esm/{stream.js → lib/stream.js} +0 -0
- /package/dist/esm/{types.js → models/types.js} +0 -0
package/LICENSE
CHANGED
|
@@ -1,21 +1,202 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.id.md
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
# ZelAI SDK Monorepo
|
|
2
|
+
|
|
3
|
+
[English](README.md) | [Bahasa Indonesia](README.id.md)
|
|
4
|
+
|
|
5
|
+
Monorepo SDK multi-bahasa resmi untuk **ZelAI OpenAI-compatible API**. Repository ini berisi SDK Node.js/TypeScript (repo ini), plus repo Go dan Deno terpisah dengan model resource yang konsisten, error handling terstruktur, dan dukungan streaming.
|
|
6
|
+
|
|
7
|
+
> **Base URL:** `https://zelapi.eu.cc/v1`
|
|
8
|
+
> **Gaya API:** Endpoint kompatibel OpenAI dengan ekstensi ZelAI
|
|
9
|
+
> **Katalog model:** Live dari `GET /v1/models` — jangan hardcode ID model
|
|
10
|
+
|
|
11
|
+
## Daftar Isi
|
|
12
|
+
|
|
13
|
+
- [Struktur Repository](#struktur-repository)
|
|
14
|
+
- [Paket](#paket)
|
|
15
|
+
- [Arsitektur](#arsitektur)
|
|
16
|
+
- [Alur Request](#alur-request)
|
|
17
|
+
- [Alur Streaming](#alur-streaming)
|
|
18
|
+
- [Alur Error Handling](#alur-error-handling)
|
|
19
|
+
- [Instalasi](#instalasi)
|
|
20
|
+
- [Quickstart per Bahasa](#quickstart-per-bahasa)
|
|
21
|
+
- [Cakupan API](#cakupan-api)
|
|
22
|
+
- [Error Handling](#error-handling)
|
|
23
|
+
- [Konfigurasi](#konfigurasi)
|
|
24
|
+
- [Development & Testing](#development--testing)
|
|
25
|
+
- [Keamanan & Best Practice](#keamanan--best-practice)
|
|
26
|
+
- [Troubleshooting](#troubleshooting)
|
|
27
|
+
- [Lisensi](#lisensi)
|
|
28
|
+
|
|
29
|
+
## Struktur Repository
|
|
30
|
+
|
|
31
|
+
```text
|
|
32
|
+
.
|
|
33
|
+
├── README.md # Dokumentasi English
|
|
34
|
+
├── README.id.md # Dokumentasi Bahasa Indonesia
|
|
35
|
+
├── package.json # npm workspace root
|
|
36
|
+
├── package-lock.json
|
|
37
|
+
└── packages/
|
|
38
|
+
├── node/ # @zelailabs/sdk (TypeScript/Node.js)
|
|
39
|
+
│ ├── src/
|
|
40
|
+
│ ├── scripts/
|
|
41
|
+
│ ├── package.json
|
|
42
|
+
│ └── tsconfig*.json
|
|
43
|
+
├── go/ # github.com/zelai/zelai-sdk-go
|
|
44
|
+
│ ├── go.mod
|
|
45
|
+
│ └── zelai/
|
|
46
|
+
└── deno/ # Deno/TypeScript SDK
|
|
47
|
+
├── deno.json
|
|
48
|
+
├── mod.ts
|
|
49
|
+
└── src/
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Paket
|
|
53
|
+
|
|
54
|
+
| Paket | Path | Registry/Import | Status |
|
|
55
|
+
|---|---|---|---|
|
|
56
|
+
| Node.js / TypeScript | `packages/node` | `@zelailabs/sdk` | Build + typecheck |
|
|
57
|
+
| Deno/JSR | standalone | [`zelapii/sdk-deno`](https://github.com/zelapii/sdk-deno) | JSR |
|
|
58
|
+
|
|
59
|
+
## Arsitektur
|
|
60
|
+
|
|
61
|
+
Monorepo ini memisahkan implementasi per bahasa, tetapi menjaga permukaan API tetap konsisten. Setiap SDK punya client dengan namespace resource (`models`, `chat.completions`, `responses`, `messages`, `systemOne`, `images`, `videos`, `audio`).
|
|
62
|
+
|
|
63
|
+
```mermaid
|
|
64
|
+
flowchart TB
|
|
65
|
+
User[Aplikasi / Kode User] --> Node[Node SDK\n@zelailabs/sdk]
|
|
66
|
+
User --> Go[Go SDK\nzelai-sdk-go]
|
|
67
|
+
User --> Deno[Deno SDK\nmod.ts]
|
|
68
|
+
|
|
69
|
+
Node --> CoreN[Client + Resources + Errors + SSE]
|
|
70
|
+
Go --> CoreG[Client + Services + Errors + SSE]
|
|
71
|
+
Deno --> CoreD[Client + Resources + Errors + SSE]
|
|
72
|
+
|
|
73
|
+
CoreN --> API[ZelAI API\nhttps://zelapi.eu.cc/v1]
|
|
74
|
+
CoreG --> API
|
|
75
|
+
CoreD --> API
|
|
76
|
+
|
|
77
|
+
API --> Models[/models/]
|
|
78
|
+
API --> Chat[/chat/completions/]
|
|
79
|
+
API --> Resp[/responses/]
|
|
80
|
+
API --> Msg[/messages/]
|
|
81
|
+
API --> Sys[/systemone/]
|
|
82
|
+
API --> Img[/images/*/]
|
|
83
|
+
API --> Vid[/videos/generations/]
|
|
84
|
+
API --> Aud[/audio/*/]
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Alur Request
|
|
88
|
+
|
|
89
|
+
Ini lifecycle umum untuk request non-streaming di semua SDK.
|
|
90
|
+
|
|
91
|
+
```mermaid
|
|
92
|
+
flowchart TD
|
|
93
|
+
A[User memanggil method SDK] --> B[Bangun URL, headers, auth, body]
|
|
94
|
+
B --> C[Terapkan timeout / abort signal / context]
|
|
95
|
+
C --> D[Kirim HTTP request]
|
|
96
|
+
D --> E{Status HTTP OK?}
|
|
97
|
+
E -- Tidak --> F[Baca error body dengan aman]
|
|
98
|
+
F --> G[Parse envelope error API jika ada]
|
|
99
|
+
G --> H[Throw/return ZelAI typed error]
|
|
100
|
+
E -- Ya --> I{Response raw/binary?}
|
|
101
|
+
I -- Ya --> J[Return raw response/bytes/ArrayBuffer]
|
|
102
|
+
I -- Tidak --> K{Content-Type JSON?}
|
|
103
|
+
K -- Ya --> L[Parse JSON dengan aman]
|
|
104
|
+
K -- Tidak --> M[Baca text dengan aman]
|
|
105
|
+
L --> N[Return data terstruktur/typed]
|
|
106
|
+
M --> N
|
|
107
|
+
D --> X{Transport/timeout/abort?}
|
|
108
|
+
X -- Ya --> Y[Wrap jadi ZelAI error dengan cause]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Alur Streaming
|
|
112
|
+
|
|
113
|
+
Streaming dipakai untuk Server-Sent Events (SSE), terutama chat completions dengan `stream: true`.
|
|
114
|
+
|
|
115
|
+
```mermaid
|
|
116
|
+
sequenceDiagram
|
|
117
|
+
participant App as Aplikasi User
|
|
118
|
+
participant SDK as ZelAI SDK
|
|
119
|
+
participant API as ZelAI API
|
|
120
|
+
|
|
121
|
+
App->>SDK: chat.completions.create(stream=true)
|
|
122
|
+
SDK->>API: POST /chat/completions (Accept: text/event-stream)
|
|
123
|
+
API-->>SDK: HTTP 200 + SSE stream
|
|
124
|
+
loop Untuk setiap event SSE
|
|
125
|
+
SDK->>SDK: Buffer baris sampai baris kosong
|
|
126
|
+
SDK->>SDK: Ambil payload data:
|
|
127
|
+
alt payload == [DONE]
|
|
128
|
+
SDK-->>App: Selesai iterasi/close
|
|
129
|
+
else JSON valid
|
|
130
|
+
SDK-->>App: Yield chunk ter-parse
|
|
131
|
+
else JSON invalid / read error
|
|
132
|
+
SDK-->>App: Raise ZelAI parse/stream error
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
SDK->>SDK: Release reader / close response
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Alur Error Handling
|
|
139
|
+
|
|
140
|
+
Semua SDK ditujukan untuk memberi error yang bisa diprediksi. Error API menyimpan metadata status/code/type/retry jika tersedia; error transport dan parsing dibungkus.
|
|
141
|
+
|
|
142
|
+
```mermaid
|
|
143
|
+
flowchart TD
|
|
144
|
+
A[Operasi dimulai] --> B{Tipe kegagalan}
|
|
145
|
+
B -->|HTTP 4xx/5xx| C[ZelAI API Error]
|
|
146
|
+
C --> C1[status]
|
|
147
|
+
C --> C2[code/type/message]
|
|
148
|
+
C --> C3[api_key_url jika ada]
|
|
149
|
+
C --> C4[retry_after dari body/header]
|
|
150
|
+
C --> C5[raw body/details/headers]
|
|
151
|
+
|
|
152
|
+
B -->|Timeout/Abort| D[ZelAI Timeout/Abort Error]
|
|
153
|
+
B -->|Network/DNS/TLS| E[ZelAI Transport Error]
|
|
154
|
+
B -->|JSON/SSE parse| F[ZelAI Parse Error]
|
|
155
|
+
B -->|Invalid usage/config| G[ZelAI Client Error]
|
|
156
|
+
|
|
157
|
+
C1 --> H[Caller: retry, reauth, perbaiki request, log]
|
|
158
|
+
D --> H
|
|
159
|
+
E --> H
|
|
160
|
+
F --> H
|
|
161
|
+
G --> H
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Instalasi
|
|
165
|
+
|
|
166
|
+
### Node.js
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
npm install @zelailabs/sdk
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Deno
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
import ZelAI from "./https://github.com/zelapii/sdk-deno/mod.ts";
|
|
176
|
+
// Setelah publish: import ZelAI from "jsr:@zelapi/sdk-deno";
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Quickstart per Bahasa
|
|
180
|
+
|
|
181
|
+
### Node.js / TypeScript
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
import ZelAI, { ZelAIError } from '@zelailabs/sdk';
|
|
185
|
+
|
|
186
|
+
const client = new ZelAI({
|
|
187
|
+
apiKey: process.env.ZELAI_API_KEY, // opsional untuk model keyless
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
try {
|
|
191
|
+
const completion = await client.chat.completions.create({
|
|
192
|
+
model: 'deepseek-v4.1-flash-free',
|
|
193
|
+
messages: [{ role: 'user', content: 'Halo dari ZelAI!' }],
|
|
194
|
+
});
|
|
195
|
+
console.log(completion.choices[0]?.message?.content);
|
|
196
|
+
} catch (err) {
|
|
197
|
+
if (err instanceof ZelAIError) {
|
|
198
|
+
console.error({ status: err.status, code: err.code, retryAfter: err.retryAfter, message: err.message });
|
|
199
|
+
}
|
|
200
|
+
throw err;
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Deno
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
import ZelAI, { ZelAIError } from "./https://github.com/zelapii/sdk-deno/mod.ts";
|
|
208
|
+
|
|
209
|
+
const client = new ZelAI({ apiKey: Deno.env.get("ZELAI_API_KEY") });
|
|
210
|
+
try {
|
|
211
|
+
const completion = await client.chat.completions.create({
|
|
212
|
+
model: "deepseek-v4.1-flash-free",
|
|
213
|
+
messages: [{ role: "user", content: "Halo dari ZelAI!" }],
|
|
214
|
+
});
|
|
215
|
+
console.log(completion.choices[0]?.message?.content);
|
|
216
|
+
} catch (err) {
|
|
217
|
+
if (err instanceof ZelAIError) console.error(err.status, err.code, err.retryAfter);
|
|
218
|
+
throw err;
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Cakupan API
|
|
223
|
+
|
|
224
|
+
| Resource | Node | Deno | Endpoint |
|
|
225
|
+
|---|---:|---:|---|
|
|
226
|
+
| Models | ✅ | ✅ | `/models`, `/models/{id}` |
|
|
227
|
+
| Chat Completions | ✅ | ✅ | `/chat/completions` |
|
|
228
|
+
| Chat Streaming (SSE) | ✅ | ✅ | `/chat/completions` |
|
|
229
|
+
| Responses | ✅ | ✅ | `/responses` |
|
|
230
|
+
| Messages | ✅ | ✅ | `/messages` |
|
|
231
|
+
| System One | ✅ | ✅ | `/systemone` |
|
|
232
|
+
| Images Generate/Edit | ✅ | ✅ | ✅ | `/images/generations`, `/images/edits` |
|
|
233
|
+
| Videos Generate | ✅ | ✅ | ✅ | `/videos/generations` |
|
|
234
|
+
| Audio Speech | ✅ | ✅ | ✅ | `/audio/speech` |
|
|
235
|
+
| Audio Transcriptions | ✅ | ✅ | ✅ | `/audio/transcriptions` |
|
|
236
|
+
| Audio Translations | ✅ | ✅ | ✅ | `/audio/translations` |
|
|
237
|
+
|
|
238
|
+
> Catatan: Beberapa endpoint bisa mengembalikan error upstream-not-configured (mis. 501) tergantung konfigurasi upstream ZelAI saat ini. SDK akan menampilkan itu sebagai API error normal.
|
|
239
|
+
|
|
240
|
+
## Error Handling
|
|
241
|
+
|
|
242
|
+
### Praktik yang disarankan
|
|
243
|
+
|
|
244
|
+
- **Periksa field terstruktur**: `status`, `code`, `type`, `message`, `retry_after/retryAfter`, `api_key_url/apiKeyUrl`.
|
|
245
|
+
- **Retry 429/5xx dengan hati-hati**: gunakan exponential backoff dan hormati `Retry-After`.
|
|
246
|
+
- **Tangani auth error**: 401/403 bisa berarti API key kosong/invalid; beberapa model keyless, beberapa butuh key.
|
|
247
|
+
- **Jangan buang cause**: SDK membungkus error transport/parse dengan cause bila didukung.
|
|
248
|
+
- **Log dengan aman**: jangan log API key atau payload sensitif.
|
|
249
|
+
|
|
250
|
+
## Konfigurasi
|
|
251
|
+
|
|
252
|
+
| Opsi | Node | Deno | Catatan |
|
|
253
|
+
|---|---|---|---|---|
|
|
254
|
+
| API key | `apiKey` | `Config.APIKey` | `apiKey` | Env: `ZELAI_API_KEY` |
|
|
255
|
+
| Base URL | `baseURL` | `Config.BaseURL` | `baseURL` | Default `https://zelapi.eu.cc/v1` |
|
|
256
|
+
| Timeout | `timeoutMs` | HTTP client/context | `timeoutMs` | Per-client atau per-request |
|
|
257
|
+
| Custom headers | `defaultHeaders` | `DefaultHeader` | `defaultHeaders` | Digabung dengan request headers |
|
|
258
|
+
| Custom HTTP client/fetch | `fetch` | `HTTPClient` | `fetch` | Berguna untuk test/proxy |
|
|
259
|
+
|
|
260
|
+
## Development & Testing
|
|
261
|
+
|
|
262
|
+
### Prasyarat
|
|
263
|
+
|
|
264
|
+
- Node.js 18+ dan npm
|
|
265
|
+
- Go 1.21+
|
|
266
|
+
- Deno 1.x/2.x (untuk test paket Deno)
|
|
267
|
+
|
|
268
|
+
### Perintah
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# dari root repo
|
|
272
|
+
npm install
|
|
273
|
+
npm run typecheck
|
|
274
|
+
npm run build
|
|
275
|
+
|
|
276
|
+
# Go tests
|
|
277
|
+
cd https://github.com/zelapii/sdk-go && GOPATH=/tmp/go GOCACHE=/tmp/go-build go test ./...
|
|
278
|
+
|
|
279
|
+
# Deno tests
|
|
280
|
+
cd https://github.com/zelapii/sdk-deno && deno test --allow-net
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## Keamanan & Best Practice
|
|
284
|
+
|
|
285
|
+
- **Jangan commit secret**: gunakan env `ZELAI_API_KEY`.
|
|
286
|
+
- **Gunakan least privilege**: expose key hanya di environment server tepercaya.
|
|
287
|
+
- **Validasi ketersediaan model**: query `/v1/models` sebelum memilih model.
|
|
288
|
+
- **Handle rate limit**: hormati `Retry-After`.
|
|
289
|
+
- **Set timeout**: hindari request menggantung di production.
|
|
290
|
+
- **Sanitasi log**: redact auth header dan konten sensitif user.
|
|
291
|
+
|
|
292
|
+
## Troubleshooting
|
|
293
|
+
|
|
294
|
+
| Gejala | Kemungkinan penyebab | Tindakan |
|
|
295
|
+
|---|---|---|
|
|
296
|
+
| `401 api_key_required` | Model butuh key atau key kosong/invalid | Set `ZELAI_API_KEY`; cek `api_key_url` |
|
|
297
|
+
| `429 rate_limited` | Terlalu banyak request | Backoff dan hormati `Retry-After` |
|
|
298
|
+
| `501 *_upstream_not_configured` | Upstream belum dikonfigurasi untuk endpoint/model | Cek ketersediaan model/endpoint di docs/katalog live |
|
|
299
|
+
| Timeout/abort error | Jaringan/upstream lambat atau timeout kecil | Naikkan timeout, retry request idempoten |
|
|
300
|
+
| JSON/SSE parse error | Format response tak terduga atau stream terputus | Periksa raw body/cause, retry, laporkan dengan request id jika ada |
|
|
301
|
+
|
|
302
|
+
## Lisensi
|
|
303
|
+
|
|
304
|
+
MIT. Lihat file LICENSE di paket terkait jika ada.
|