Report DSPy optimizer steps
import requests
url = "https://app.langwatch.ai/api/dspy/log_steps"
payload = [
{
"run_id": "<string>",
"index": "<string>",
"score": 123,
"label": "<string>",
"optimizer": {
"name": "<string>",
"parameters": {}
},
"predictors": [
{
"name": "<string>",
"predictor": { "__class__": "<string>" }
}
],
"timestamps": { "created_at": 123 },
"examples": [
{
"example": { "__class__": "<string>" },
"pred": { "__class__": "<string>" },
"score": 123,
"trace": [
{
"input": { "__class__": "<string>" },
"pred": { "__class__": "<string>" }
}
]
}
],
"llm_calls": [
{
"__class__": "<string>",
"response": { "__class__": "<string>" },
"model": "<string>",
"prompt_tokens": 123,
"completion_tokens": 123,
"cost": 123
}
],
"workflow_version_id": "<string>",
"experiment_id": "<string>",
"experiment_slug": "<string>"
}
]
headers = {
"X-Auth-Token": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Auth-Token': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify([
{
run_id: '<string>',
index: '<string>',
score: 123,
label: '<string>',
optimizer: {name: '<string>', parameters: {}},
predictors: [{name: '<string>', predictor: {__class__: '<string>'}}],
timestamps: {created_at: 123},
examples: [
{
example: {__class__: '<string>'},
pred: {__class__: '<string>'},
score: 123,
trace: [{input: {__class__: '<string>'}, pred: {__class__: '<string>'}}]
}
],
llm_calls: [
{
__class__: '<string>',
response: {__class__: '<string>'},
model: '<string>',
prompt_tokens: 123,
completion_tokens: 123,
cost: 123
}
],
workflow_version_id: '<string>',
experiment_id: '<string>',
experiment_slug: '<string>'
}
])
};
fetch('https://app.langwatch.ai/api/dspy/log_steps', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request POST \
--url https://app.langwatch.ai/api/dspy/log_steps \
--header 'Content-Type: application/json' \
--header 'X-Auth-Token: <api-key>' \
--data '
[
{
"run_id": "<string>",
"index": "<string>",
"score": 123,
"label": "<string>",
"optimizer": {
"name": "<string>",
"parameters": {}
},
"predictors": [
{
"name": "<string>",
"predictor": {
"__class__": "<string>"
}
}
],
"timestamps": {
"created_at": 123
},
"examples": [
{
"example": {
"__class__": "<string>"
},
"pred": {
"__class__": "<string>"
},
"score": 123,
"trace": [
{
"input": {
"__class__": "<string>"
},
"pred": {
"__class__": "<string>"
}
}
]
}
],
"llm_calls": [
{
"__class__": "<string>",
"response": {
"__class__": "<string>"
},
"model": "<string>",
"prompt_tokens": 123,
"completion_tokens": 123,
"cost": 123
}
],
"workflow_version_id": "<string>",
"experiment_id": "<string>",
"experiment_slug": "<string>"
}
]
'{
"message": "<string>"
}{
"message": "<string>",
"error": "<string>"
}{
"message": "<string>"
}{
"error": "<string>",
"message": "<string>",
"fault": "<string>",
"tips": [
"<string>"
],
"docsUrl": "<string>"
}{
"message": "<string>",
"error": "<string>"
}Experiments
Report DSPy optimizer steps
Report the steps of a DSPy optimizer run against an experiment, so the run’s progress and scores show up in the app. Send the steps as an array; the optimizer typically posts each batch as it finishes. Bodies up to 20MB are accepted.
POST
/
api
/
dspy
/
log_steps
Report DSPy optimizer steps
import requests
url = "https://app.langwatch.ai/api/dspy/log_steps"
payload = [
{
"run_id": "<string>",
"index": "<string>",
"score": 123,
"label": "<string>",
"optimizer": {
"name": "<string>",
"parameters": {}
},
"predictors": [
{
"name": "<string>",
"predictor": { "__class__": "<string>" }
}
],
"timestamps": { "created_at": 123 },
"examples": [
{
"example": { "__class__": "<string>" },
"pred": { "__class__": "<string>" },
"score": 123,
"trace": [
{
"input": { "__class__": "<string>" },
"pred": { "__class__": "<string>" }
}
]
}
],
"llm_calls": [
{
"__class__": "<string>",
"response": { "__class__": "<string>" },
"model": "<string>",
"prompt_tokens": 123,
"completion_tokens": 123,
"cost": 123
}
],
"workflow_version_id": "<string>",
"experiment_id": "<string>",
"experiment_slug": "<string>"
}
]
headers = {
"X-Auth-Token": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Auth-Token': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify([
{
run_id: '<string>',
index: '<string>',
score: 123,
label: '<string>',
optimizer: {name: '<string>', parameters: {}},
predictors: [{name: '<string>', predictor: {__class__: '<string>'}}],
timestamps: {created_at: 123},
examples: [
{
example: {__class__: '<string>'},
pred: {__class__: '<string>'},
score: 123,
trace: [{input: {__class__: '<string>'}, pred: {__class__: '<string>'}}]
}
],
llm_calls: [
{
__class__: '<string>',
response: {__class__: '<string>'},
model: '<string>',
prompt_tokens: 123,
completion_tokens: 123,
cost: 123
}
],
workflow_version_id: '<string>',
experiment_id: '<string>',
experiment_slug: '<string>'
}
])
};
fetch('https://app.langwatch.ai/api/dspy/log_steps', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request POST \
--url https://app.langwatch.ai/api/dspy/log_steps \
--header 'Content-Type: application/json' \
--header 'X-Auth-Token: <api-key>' \
--data '
[
{
"run_id": "<string>",
"index": "<string>",
"score": 123,
"label": "<string>",
"optimizer": {
"name": "<string>",
"parameters": {}
},
"predictors": [
{
"name": "<string>",
"predictor": {
"__class__": "<string>"
}
}
],
"timestamps": {
"created_at": 123
},
"examples": [
{
"example": {
"__class__": "<string>"
},
"pred": {
"__class__": "<string>"
},
"score": 123,
"trace": [
{
"input": {
"__class__": "<string>"
},
"pred": {
"__class__": "<string>"
}
}
]
}
],
"llm_calls": [
{
"__class__": "<string>",
"response": {
"__class__": "<string>"
},
"model": "<string>",
"prompt_tokens": 123,
"completion_tokens": 123,
"cost": 123
}
],
"workflow_version_id": "<string>",
"experiment_id": "<string>",
"experiment_slug": "<string>"
}
]
'{
"message": "<string>"
}{
"message": "<string>",
"error": "<string>"
}{
"message": "<string>"
}{
"error": "<string>",
"message": "<string>",
"fault": "<string>",
"tips": [
"<string>"
],
"docsUrl": "<string>"
}{
"message": "<string>",
"error": "<string>"
}Authorizations
Project API key for sending traces and accessing project-scoped resources. Format: sk-lw-... (no underscore). Obtain one by creating a project via the Admin API or the LangWatch UI.
Body
application/json
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Response
Every step in the batch was recorded
Human-readable confirmation
Was this page helpful?
⌘I