/streams/:channel returning inconsistant results

I feel like there is something very weird going on with the /streams/:channel REST API endpoint. I am trying to access it via PHP and experiencing intermittant errors. When I look at the raw JSON response, it seems to be changing every time the endpoint is called!

Example:
Loading https://api.twitch.tv/kraken/streams/wcs_america gives me

{
    "stream": {
        "viewers": 15771,
        "channel": {
            "profile_banner": null,
            "background": "http://static-cdn.jtvnw.net/jtv_user_pictures/wcs_america-channel_background_image-ca7b9b4c0b7c3a3e.jpeg",
            "status": "WCS America Challenger League - Group D - HwangSin, puCK, mOOnGLaDe",
            "display_name": "WCS America",
            "video_banner": "http://static-cdn.jtvnw.net/jtv_user_pictures/wcs_america-channel_offline_image-fb60322ea62f2a4d-640x360.jpeg",
            "game": "StarCraft II: Heart of the Swarm",
            "_id": 42384075,
            "banner": null,
            "url": "http://www.twitch.tv/wcs_america",
            "created_at": "2013-04-12T21:29:29Z",
            "name": "wcs_america",
            "delay": 300,
            "_links": {
                "editors": "https://api.twitch.tv/kraken/channels/wcs_america/editors",
                "chat": "https://api.twitch.tv/kraken/chat/wcs_america",
                "commercial": "https://api.twitch.tv/kraken/channels/wcs_america/commercial",
                "subscriptions": "https://api.twitch.tv/kraken/channels/wcs_america/subscriptions",
                "teams": "https://api.twitch.tv/kraken/channels/wcs_america/teams",
                "self": "https://api.twitch.tv/kraken/channels/wcs_america",
                "features": "https://api.twitch.tv/kraken/channels/wcs_america/features",
                "videos": "https://api.twitch.tv/kraken/channels/wcs_america/videos",
                "stream_key": "https://api.twitch.tv/kraken/channels/wcs_america/stream_key",
                "follows": "https://api.twitch.tv/kraken/channels/wcs_america/follows"
            },
            "logo": "http://static-cdn.jtvnw.net/jtv_user_pictures/wcs_america-profile_image-3ecad20be0179336-300x300.jpeg",
            "mature": null,
            "updated_at": "2013-08-29T21:30:21Z"
        },
        "preview": {
            "small": "http://static-cdn.jtvnw.net/previews-ttv/live_user_wcs_america-80x50.jpg",
            "template": "http://static-cdn.jtvnw.net/previews-ttv/live_user_wcs_america-{width}x{height}.jpg",
            "medium": "http://static-cdn.jtvnw.net/previews-ttv/live_user_wcs_america-320x200.jpg",
            "large": "http://static-cdn.jtvnw.net/previews-ttv/live_user_wcs_america-640x400.jpg"
        },
        "game": "StarCraft II: Heart of the Swarm",
        "_id": 6663367440,
        "_links": {
            "self": "https://api.twitch.tv/kraken/streams/wcs_america"
        }
    },
    "_links": {
        "channel": "https://api.twitch.tv/kraken/channels/wcs_america",
        "self": "https://api.twitch.tv/kraken/streams/wcs_america"
    }

}

But if I just refresh the page and load the exact same endpoint a few seconds later, I get this:

{

    "_links": {
        "channel": "https://api.twitch.tv/kraken/channels/wcs_america",
        "self": "https://api.twitch.tv/kraken/streams/wcs_america"
    },
    "stream": {
        "_links": {
            "self": "https://api.twitch.tv/kraken/streams/wcs_america"
        },
        "preview": "http://static-cdn.jtvnw.net/previews-ttv/live_user_wcs_america-320x200.jpg",
        "_id": 6663367440,
        "viewers": 10044,
        "broadcaster": "delay",
        "game": "StarCraft II: Heart of the Swarm",
        "channel": {
            "_links": {
                "editors": "https://api.twitch.tv/kraken/channels/wcs_america/editors",
                "chat": "https://api.twitch.tv/kraken/chat/wcs_america",
                "subscriptions": "https://api.twitch.tv/kraken/channels/wcs_america/subscriptions",
                "features": "https://api.twitch.tv/kraken/channels/wcs_america/features",
                "self": "https://api.twitch.tv/kraken/channels/wcs_america",
                "commercial": "https://api.twitch.tv/kraken/channels/wcs_america/commercial",
                "videos": "https://api.twitch.tv/kraken/channels/wcs_america/videos",
                "stream_key": "https://api.twitch.tv/kraken/channels/wcs_america/stream_key",
                "follows": "https://api.twitch.tv/kraken/channels/wcs_america/follows"
            },
            "display_name": "WCS America",
            "mature": null,
            "status": "WCS America Challenger League - Group D - HwangSin, puCK, mOOnGLaDe",
            "updated_at": "2013-08-29T21:30:21Z",
            "_id": 42384075,
            "created_at": "2013-04-12T21:29:29Z",
            "banner": null,
            "game": "StarCraft II: Heart of the Swarm",
            "teams": [
                {
                    "_links": {
                        "self": "https://api.twitch.tv/kraken/teams/wcs"
                    },
                    "display_name": "StarCraft II - World Championship Series",
                    "updated_at": "2013-06-04T00:05:54Z",
                    "_id": 363,
                    "info": "<a rel=\"nofollow\" href=\"https://bnetcmsus-a.akamaihd.net/cms/gallery/R35VBBI4S54S1370295085225.jpg\" target=\"_blank\"><img src=\"http://i.imgur.com/AJ2GR4j.jpg?1\" alt=\"WCS_Schedule EDT.jpg\" /></a> <br /><center><i>Click the above image for a full resolution schedule</i></center>\n<br /><a rel=\"nofollow\" href=\"http://us.battle.net/sc2/en/blog/9355170/StarCraft_II_World_Championship_Series_2013-4_2_2013\" target=\"_blank\"><img src=\"http://i.imgur.com/37H4qOI.jpg\" alt=\"37H4qOI.jpg\" /></a>\n<br />\n",
                    "created_at": "2012-07-26T23:18:06Z",
                    "banner": "http://static-cdn.jtvnw.net/jtv_user_pictures/team-wcs-banner_image-604726ea3b15c53f-640x125.jpeg",
                    "name": "wcs",
                    "logo": "http://static-cdn.jtvnw.net/jtv_user_pictures/team-wcs-team_logo_image-e8bd14693a200a47-300x300.jpeg",
                    "background": "http://static-cdn.jtvnw.net/jtv_user_pictures/team-wcs-background_image-d8f37e2cb2218d60.jpeg"
                }
            ],
            "logo": "http://static-cdn.jtvnw.net/jtv_user_pictures/wcs_america-profile_image-3ecad20be0179336-300x300.jpeg",
            "name": "wcs_america",
            "video_banner": "http://static-cdn.jtvnw.net/jtv_user_pictures/wcs_america-channel_offline_image-fb60322ea62f2a4d-640x360.jpeg",
            "url": "http://www.twitch.tv/wcs_america",
            "background": "http://static-cdn.jtvnw.net/jtv_user_pictures/wcs_america-channel_background_image-ca7b9b4c0b7c3a3e.jpeg"
        },
        "name": "live_user_wcs_america"
    }

}

Which is organized completely differently and even has different information. The first time it provided different preview image sizes but no team information. The second time loading the exact same url gives all the team information but it only provides a single preview image. Looking at the http headers I can see that I am getting the v3 API response in both cases. If I load the endpoint again, I get yet another response, different from the other two. What elements are in the response and their order seems to be almost random.

Does anyone know what is going on here?

I think that would be the difference between API v2 and v3. The API version 2 provided information on teams within the streams object, but they may have removed it in the v3 API. The documentation shows that teams is still provided in the object, but I have not seen this. I also saw from my own testing (and you see it as well) that the v3 and v2 APIs were being served interchangeably. I don’t think it is meant to show v2 info by default, but you can send a version header to fix this issue (I think). The order of results is normal, since it shouldn’t matter what order they are in.

What night said, the difference that you see here is v2 response and v3 response.

This happens because of a caching bug we’re looking into that will serve you a v2 response even if you ask for a v3 response.

Ok, Good to know. I guess I will just have to take either response into account when loading the information.

This should be fixed! Thanks for the bug report.