@spicyapi/sdk 0.1.0 → 0.2.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/README.md +63 -2
- package/contracts/openapi.yaml +703 -21
- package/dist/src/docs/index.d.ts.map +1 -1
- package/dist/src/docs/index.js +20 -2
- package/dist/src/docs/index.js.map +1 -1
- package/dist/src/generated/openapi.d.ts +842 -18
- package/dist/src/generated/openapi.d.ts.map +1 -1
- package/dist/src/sdk/client.d.ts +3 -2
- package/dist/src/sdk/client.d.ts.map +1 -1
- package/dist/src/sdk/client.js +36 -25
- package/dist/src/sdk/client.js.map +1 -1
- package/dist/src/sdk/response-body.d.ts +4 -0
- package/dist/src/sdk/response-body.d.ts.map +1 -0
- package/dist/src/sdk/response-body.js +46 -0
- package/dist/src/sdk/response-body.js.map +1 -0
- package/dist/src/sdk/types.d.ts +5 -3
- package/dist/src/sdk/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Official TypeScript SDK for the SpicyAPI public API. It contains the typed client, webhook
|
|
4
4
|
verification helpers, documentation index, and generated OpenAPI types. It does not install the CLI,
|
|
5
|
-
MCP server, or
|
|
5
|
+
MCP server, or Agent Skill.
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install @spicyapi/sdk
|
|
@@ -16,6 +16,67 @@ const models = await client.listModels({ includeSchema: true });
|
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
Set `SPICY_API_KEY` with your process secret manager. Task creation and retry may reserve funds; use
|
|
19
|
-
stable idempotency keys and explicit user confirmation.
|
|
19
|
+
stable idempotency keys and explicit user confirmation. Call `quoteTask` with the exact request
|
|
20
|
+
first, display its `estimatedCost`, `maxCharge` and `expiresAt`, then call `createTask` with the
|
|
21
|
+
unchanged input, `quoteId` and `expectedCost`.
|
|
20
22
|
|
|
21
23
|
Documentation: <https://spicyapi.ai/en/docs>
|
|
24
|
+
|
|
25
|
+
## Chat and LLM streaming
|
|
26
|
+
|
|
27
|
+
Use the official `openai` client for `/v1/chat/completions`; install it separately with
|
|
28
|
+
`npm install openai`. The native SDK intentionally keeps tasks, quotes and uploads in one small
|
|
29
|
+
client. It does not reimplement the OpenAI streaming protocol.
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import OpenAI from "openai";
|
|
33
|
+
|
|
34
|
+
const client = new OpenAI({
|
|
35
|
+
apiKey: process.env.SPICY_API_KEY,
|
|
36
|
+
baseURL: "https://api.spicyapi.ai/v1",
|
|
37
|
+
maxRetries: 0,
|
|
38
|
+
});
|
|
39
|
+
const signal = AbortSignal.timeout(120_000);
|
|
40
|
+
const stream = await client.chat.completions.create(
|
|
41
|
+
{
|
|
42
|
+
model: process.env.SPICY_MODEL,
|
|
43
|
+
messages: [{ role: "user", content: "Explain a rainbow in one sentence." }],
|
|
44
|
+
stream: true,
|
|
45
|
+
stream_options: { include_usage: true },
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
signal,
|
|
49
|
+
headers: { "Idempotency-Key": process.env.SPICY_IDEMPOTENCY_KEY },
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
try {
|
|
53
|
+
for await (const chunk of stream) {
|
|
54
|
+
process.stdout.write(chunk.choices[0]?.delta.content ?? "");
|
|
55
|
+
if (chunk.usage) process.stderr.write(JSON.stringify(chunk.usage) + "\n");
|
|
56
|
+
}
|
|
57
|
+
} finally {
|
|
58
|
+
stream.controller.abort();
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The abort signal covers stream consumption as well as connection setup. Aborting stops the local
|
|
63
|
+
stream; it does not cancel an accepted task or promise a refund. With `stream: false`, read
|
|
64
|
+
`choices[0].message.content`. In a tool conversation, accumulate tool-call fragments by index and
|
|
65
|
+
preserve the complete assistant message before adding matching `tool_call_id` results. Only enable
|
|
66
|
+
tools or reasoning fields when the model schema supports them.
|
|
67
|
+
|
|
68
|
+
CLI and MCP currently submit and track native tasks; they do not expose live chat token streaming.
|
|
69
|
+
Use this client path for a token-by-token interface, or native `jobs/stream` when you need quote
|
|
70
|
+
confirmation and the platform event envelope.
|
|
71
|
+
|
|
72
|
+
Select `SPICY_MODEL` from the live model schema. Keep API keys on your server and persist
|
|
73
|
+
`SPICY_IDEMPOTENCY_KEY` for the same logical action; disable automatic retries to avoid silently
|
|
74
|
+
repeating a billable operation. Compatibility requests use the price at acceptance. Use native
|
|
75
|
+
`quoteTask` and `createTask` when confirming `expectedCost` is required.
|
|
76
|
+
|
|
77
|
+
Reasoning-capable models may return `delta.reasoning_content`; it is optional and may need an
|
|
78
|
+
explicit type extension in the official client. Reasoning tokens are already included in
|
|
79
|
+
`completion_tokens`. Stream completion is not proof of financial settlement.
|
|
80
|
+
|
|
81
|
+
[Complete compatibility guide](https://spicyapi.ai/en/docs/quotes-and-compatibility) ·
|
|
82
|
+
[Official JavaScript client](https://github.com/openai/openai-node)
|