Polimorf Docs
API Reference

Ad-hoc generation

POST /runtime/execute and /runtime/stream — run a generation by specifying the provider, model, and messages on each request.

Run a generation where the client supplies everything: the provider, the model, and the full message list. Use this when the caller owns the configuration; for configuration managed by your team, use a deployed assistant instead.

POST /runtime/execute

Runs one non-streaming generation and returns the complete result.

Request body

FieldTypeRequiredDescription
providerNamestringyesTarget provider, e.g. openai or anthropic.
modelstringyesProvider model identifier, e.g. gpt-4o.
messagesarrayyesOrdered conversation; at least one message.
messages[].rolesystem | user | assistantyesMessage author role.
messages[].contentstringyesMessage text.
configobjectnoGeneration settings (below); defaults to {}.

config

FieldTypeDescription
temperaturenumberSampling temperature.
maxOutputTokensnumberCap on generated tokens.
responseFormattext | jsonForce plain text or JSON output.
timeoutMsnumberPer-generation timeout.
maxRetriesnumberProvider retry budget.

Example request

curl https://api.polimorf.app/runtime/execute \
  -H "Authorization: Bearer $POLIMORF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "providerName": "openai",
    "model": "gpt-4o",
    "messages": [
      { "role": "system", "content": "You are a concise assistant." },
      { "role": "user", "content": "Explain embeddings in one sentence." }
    ],
    "config": { "temperature": 0.2, "maxOutputTokens": 200 }
  }'

Response

{
  "message": { "role": "assistant", "content": "An embedding is a…" },
  "finishReason": "stop",
  "usage": { "inputTokens": 24, "outputTokens": 18, "totalTokens": 42 }
}
FieldTypeDescription
messageobjectThe generated message (role, content).
finishReasonstringstop, length, tool_calls, content_filter, or error.
usageobjectToken accounting: inputTokens, outputTokens, totalTokens.

With the SDK

const result = await client.runtime.execute({
  providerName: 'openai',
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'Explain embeddings in one sentence.' }],
  config: { temperature: 0.2 },
});

Streaming

POST /runtime/stream

Identical request body to /runtime/execute, but the response is a Server-Sent Events stream of deltausagedone events (or a terminal error).

for await (const event of client.runtime.stream({
  providerName: 'openai',
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'Write a haiku about the sea.' }],
})) {
  if (event.type === 'delta') process.stdout.write(event.content);
}

See Streaming for the full event contract and cancellation.