Skip to content
engineering workbench.by StudyPort Academy
Learning path
Advanced18 min

Calling an AI service from your backend

Understand the idea

The route does not invent the summary. It sends a request and reads one field from the provider JSON.

The idea

The handler POSTs JSON to /v1/chat with a messages array and an Authorization header. The stand-in in this process speaks that shape and returns Summary: plus the text you sent. fetch is a real HTTP . The URL is 127.0.0.1 because this runner has no provider key, and lesson 20 is why that key is not pasted here. Point the same function at a real host later, and read the key from the environment. The the route returns to the client is only the content string, not the provider envelope.

What changes

Piece of the call
PieceIn this runIn production
Method and pathPOST /v1/chatThe provider path you were given
Bodymodel and messagesThe same shape, your model name
AuthorizationBearer demoBearer and the environment key
Text you keepchoices[0].message.contentThe same field, after the next lessons check it

The command

Summarize Milk

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

The mistake

Check the result

Status 200 and summary Summary: Milk. The stand-in saw the message text Milk.

Guided challenge

Prefix the model text with Summary

The stand-in returns Note: plus the prompt. Change that prefix to Summary: so the route returns Summary: Milk.

Prefix the model text with Summary

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

EXPECTED RESULT

status 200
Summary: Milk

Hints 0/2

    Use all hints or make 3 failed checks (0/3).

    Free exploration

    Change this example and run it again. Each run is a new process. Nothing is saved.

    Your variation

    3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01Where does the summary text live in this response shape?
    02Why is the provider in this run on 127.0.0.1?

    Ready to call this one understood?

    Mark this lesson complete to earn 200 XP. You can always revisit it.

    Sign in to save progress
    Next lesson