Streaming Completion

Creates a streaming chat completion. Set stream=true to receive responses as they are generated.

POST /v1/chat/completions

Request Body

Les paramètres suivants peuvent être inclus dans le corps de la requête :

Paramètres

model
string
Required
Default Value: alphaedge-large-3-2512

ID of the model to use.

messages
array<Message>
Required

A list of messages comprising the conversation so far.

stream
boolean
Required
Default Value: true

Whether to stream back partial progress. Must be true for streaming.

Successful Response

Les champs suivants sont retournés dans une réponse réussie :

Champs de réponse

id
string
Required

A unique identifier for the completion.

object
string
Required

The object type, which is "chat.completion.chunk" for streaming.

created
integer
Required

The Unix timestamp of when the completion was created.

model
string
Required

The model used for the completion.

choices
array<Choice>
Required

The list of completion choices.

Examples

Exemples de code pour utiliser cet endpoint :

typescript
import { AlphaEdge } from '@alphaedge/alphaedge';

const alphaedge = new AlphaEdge({
  apiKey: process.env.ALPHAEDGE_API_KEY,
});

const stream = await alphaedge.chat.completions.create({
  model: 'alphaedge-large-3-2512',
  messages: [{ role: 'user', content: 'Hello!' }],
  stream: true
});

for await (const chunk of stream) {
  console.log(chunk.choices[0].delta.content);
}
python
from alphaedge import AlphaEdge

alphaedge = AlphaEdge(api_key="your-api-key")

stream = alphaedge.chat.completions.create(
    model="alphaedge-large-3-2512",
    messages=[{"role": "user", "content": "Hello!"}],
    stream=True
)

for chunk in stream:
    print(chunk.choices[0].delta.content)
curl
curl https://api.alphaedge-ai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ALPHAEDGE_API_KEY" \
  -d '{
    "model": "alphaedge-large-3-2512",
    "messages": [{"role": "user", "content": "Hello!"}],
    "stream": true
  }' 

Response

Exemple de réponse de l'API :

json
{
  "id": "chat-abc123",
  "object": "chat.completion.chunk",
  "created": 1234567890,
  "model": "alphaedge-large-3-2512",
  "choices": [
    {
      "index": 0,
      "delta": {
        "content": "Hello"
      },
      "finish_reason": null
    }
  ]
}
text
data: {"id":"chat-abc123","object":"chat.completion.chunk","created":1234567890,"model":"alphaedge-large-3-2512","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}

data: {"id":"chat-abc123","object":"chat.completion.chunk","created":1234567890,"model":"alphaedge-large-3-2512","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}

data: [DONE]